export default {
data() {
return {
options1: [
{
text: "删除",
},
],
};
},
};
import { reactive } from 'vue';
export default {
setup() {
const state = reactive({
options1: [
{
text: "删除",
},
],
});
return { state };
},
};
该回答引用GPTᴼᴾᴱᴺᴬᴵ
在Vue 3中,你可以使用setup()函数来代替data()函数,并将数据暴露为响应式对象。代码如下:
<script>
import { reactive } from 'vue';
export default {
setup() {
const state = reactive({
options1: [
{
text: "删除",
},
],
});
return { state };
},
};
</script>
请注意,我们使用reactive函数来创建响应式对象state。setup()函数还需要返回我们想要暴露的任何属性或方法,这里我们返回了state。在模板中访问数据的方式也稍微有些不同。在Vue 3中,我们使用state.options1来代替this.options1。
参考如下:
import { reactive } from "vue";
export default {
setup() {
const state = reactive({
options1: [
{
text : "删除"
},
]
});
return {state};
}
}