我有一个用 Vue 编写的简单应用程序。我想要的只是在 Vue.createApp() 方法之外调用 Vue 中的一个自定义方法。
我的代码:
const app = Vue.createApp({
data() {
return {
data: ["this","is","an", "example"],
}
},
methods: {
getData() {
return this.data;
},
},
});
app.mount('#app');
// This instruction fails!
console.log(app.getData());
Run Code Online (Sandbox Code Playgroud)
当我尝试执行最后一行的方法时,我进入控制台:
Uncaught TypeError: Cannot read property 'content' of undefined
Run Code Online (Sandbox Code Playgroud)
为什么我无法执行该方法?怎么了?