如何将道具从另一个js模块传递到Vuejs?

问题描述 投票:0回答:1

是否可以将道具从任何js模块传递到vue?

道具对我来说在组件之间传递得很好,但是不是从实际的Vue应用程序本身传递的:

main.js

import Vue from 'vue'
import App from './App.vue'


var myVue = new Vue({  export to other files
  el: '#entry',
  components: {App},
  render: h => h(App),
  data: function(){
    return{
      testSuccess:'this test was successful!'
    }
  },
})

window.myVue = myVue // we use window.myVue becayse if we can export to window, we can export to other js modules.

App.vue

<template>
  <div ref="app">
    {{ testSuccess ? testSuccess : 'prop not imported!' }}
  </div>
</template>

<script>
export default = {
  name: "app",
  props: ["testSuccess"]
}
</script>

index.html

<div id="entry" >
  <app :testSuccess="testSuccess"></app>
</div>
<script src="/dist/build.js"></script>

我想念什么?

我了解如何使用组件执行此操作。

我希望能够将Vue模块导出到其他js模块并将有意义的信息传递给它。

javascript vue.js
1个回答
0
投票

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.