如何在NuxtJs应用程序中使用Vue.set()?

Ily*_* Vo 0 vue.js vuejs2 nuxt.js

我将在Nuxtjs应用程序中通过Vue.set()设置属性。

editPost(post) {
    Vue.$set(post, 'edit', true)
}
Run Code Online (Sandbox Code Playgroud)

得到错误:未定义Vue

Ald*_*und 5

您可以使用this代替Vue.。这引用了方法内部的当前vue组件,因此它将以相同的方式工作:

editPost(post) {
    this.$set(post, 'edit', true)
}
Run Code Online (Sandbox Code Playgroud)