【发布时间】:2021-07-03 21:48:14
【问题描述】:
我有这个 .ts 文件:
import { reactive, toRefs } from 'vue'
export const TitleComponent = () => {
const obj = reactive({
title: "This should be reactive"
})
const updateObj = () => {
obj.title = 'This is now different'
}
return {...toRefs(obj), updateObj }
}
然后我导入到一个显示它的 vue 组件中
<template>
<h1>{{ title }}</h1>
</template>
import { defineComponent } from 'vue'
import { TitleComponent } from 'some/place'
export default defineComponent({
const { title } = TitleComponent()
return { title }
})
然后,我在另一个运行该方法的组件中使用函数updateObj。但它不会更新标题值。什么给了?
<template>
<button @click="updateObj">Click Me</button>
</template>
import { defineComponent } from 'vue'
import { TitleComponent } from 'some/place'
export default defineComponent({
const { updateObj } = TitleComponent()
return { updateObj}
})
【问题讨论】:
标签: javascript vuejs3