useMeta composable
useMeta composable是Quasar Meta Plugin的一部分。如果你现在还没有深入研究它,请先阅读一下那里。
语法
对于静态meta配置(非响应式):
import { useMeta } from 'quasar'
setup () {
useMeta({ /* meta config */ })
}
对于动态meta配置(响应式):
import { useMeta } from 'quasar'
setup () {
// essentially acting as a computed property
useMeta(() => {
// compute or reference other stuff
// in your component
// then return:
return { /* meta config */ }
})
}
例子
<script>
import { useMeta } from 'quasar'
export default {
setup () {
const title = ref('Some title') // we define the "title" prop
// NOTICE the parameter here is a function
// Under the hood, it is converted to a Vue computed prop for reactivity
useMeta(() => {
return {
// whenever "title" from above changes, your meta will automatically update
title: title.value
}
})
function setAnotherTitle () {
title.value = 'Another title' // will automatically trigger a Meta update due to the binding
}
return {
setAnotherTitle
}
}
}
</script>