簡體   English   中英

VueJS:如何在模板中使用main.js中的數據?

[英]VueJS: How do I use data from main.js in my templates?

我的main.js中有Vue范圍:

new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App },
  data: {
    name: 'Levi'
  }
})

我想在我的模板中使用它: test.vue

<p>My name is {{ name }}

我將vue-router用於所有路由功能,並且一切正常。 但是當我嘗試在模板中調用name ,我得到了

[Vue warn]: Property or method "name" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.

任何幫助將不勝感激。 謝謝。

只需在我的模板中添加腳本標簽並使用module.exportsexport default

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM