API 浏览器
useMeta 组合

useMeta 可组合项是 Quasar Meta 插件 的一部分。如果你现在还没有深入了解,请先阅读那里的内容。

¥The useMeta composable is part of Quasar Meta Plugin. If you haven’t dug into it by now, please have a first read there.

语法(Syntax)

¥Syntax

对于静态元配置(非响应式):

¥For static meta configuration (non-reactive):

import { useMeta } from 'quasar'

setup () {
  useMeta({ /* meta config */ })
}

对于动态元配置(响应式):

¥For dynamic meta configuration (reactive):

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 */ }
  })
}

示例(Example)

¥Example

<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>