简体   繁体   English

将属性从 main.ts 传递到 Vue 3 应用程序的根组件

[英]Pass property into root component of Vue 3 app from main.ts

I try to pass a boolean property to App.vue from inside main.ts我尝试将 boolean 属性从 main.ts 内部传递给 App.vue

main.ts:主.ts:

const freshchatActive = false;

new Vue({
  router,
  store,
  i18n,
  vuetify,
  props: { freshchatActive: Boolean },
  render: h => h(App),
}).$mount("#app");

App.Vue: App.Vue:

export default class App extends Vue {
  @Prop({ default: () => false }) freshchatActive!: boolean;

  created() {
    console.log("created #freshchatActive", this.freshchatActive);
  }

However, the console always prints the default value (false).但是,控制台始终打印默认值 (false)。 How would I pass in the property when creating the application root component in main.ts?在 main.ts 中创建应用程序根组件时如何传入属性?

Thanks in advance for your suggestions.提前感谢您的建议。

Kind Regards Stephan亲切的问候斯蒂芬

As you are using the render function, you need to pass the props to the h function like当您使用渲染器 function 时,您需要将道具传递给h function,例如

new Vue({
  router,
  store,
  i18n,
  vuetify,
  render: h => 
    h(App, { 
      freshchatActive: true 
    }),
}).$mount("#app");

Just to clarify, the way the app is initialized is not Vue 3 as mentioned in my comments.澄清一下,应用程序的初始化方式不是我评论中提到的 Vue 3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM