You are viewing a single comment's thread from:

RE: Nuxt开发指南

in #starnoteyesterday
//ref() 和 computed() 被自动导入
const count = ref(1)
const double = computed(() => count.value * 2)

//使用computed监听路由变化
const route = useRoute()
const pageKey = computed(()=>route.fullPath)
const activeName = computed(()=>route.name)


//使用watch监听路由变化
watch(route, (to) => {
  console.log('路由',to)
}, {flush: 'pre', immediate: true, deep: true})


// 使用watch监听数据变化,做出相应逻辑
watch(tagOption, () => {
  console.log(6688, 'tagOption2', tagOption.value[[tagOption.value.length - 1]])
  tagsX.value += tagOption.value[[tagOption.value.length - 1]]
}, {flush: 'pre', immediate: true, deep: true})


//使用watch监听路由变化,即刻获取数据,渲染页面
// 每当进入页面都会发生一次 watch
// 每当 keywords 数据发生一次变化,就会发生一次 watch
watch(()=>route.query.keywords,(newVal)=>{
    keywords.value = newVal
    getData()
}, {flush: 'pre', immediate: true, deep: true})