useMeta 可组合函数是 Quasar 元数据插件 的一部分。如果您还没有深入了解它,请先在那里阅读。
语法
用于静态元数据配置(非响应式)
import { useMeta } from 'quasar'
setup () {
useMeta({ /* meta config */ })
}
内容粘贴
用于动态元数据配置(响应式)
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>
内容粘贴