如何将VUE中的自定义组件设置为自定义组件

发布于 2025-02-07 21:58:48 字数 906 浏览 1 评论 0原文

您好,我试图使用DOM将自定义VUE组件添加到模板中,我已经设置了属性,但是我无法在自定义组件中设置事件的关联属性。这是我的buttonvue.vue component(Child component)

export default {
emits:['action','isAuth'],
data:function(){
    return {msg:this.textDisplay()}
},
 methods:{
    textDisplay(){
        return this.$emit('isAuth')?'Sign in with Microsoft':'Sign out from Microsoft'
    }
 }
}
</script>

parent> parent component:

 insertBtnComponent){
    var ComponentClass = Vue.extend(buttonVue)
    var instance = new ComponentClass({
    propsData:{class:"buttonMs" ,style:" position: static ;",
    'action':this.isUserAuthenticated()?this.signOut():this.signInUser(),
    'isAuth':this.isUserAuthenticated()
   }
 })
  let selector = document.querySelector(".classNAMEofDiv");
  instance.$mount()
  selector.appendChild(instance.$el)

我很感谢我的问题提示,谢谢。

Hello I'm trying to add a custom Vue component to my template using the DOM, I already setted the properties, but I can't set the associated attribute of events in the custom component. Here is my buttonVue.vue component (child component) :

export default {
emits:['action','isAuth'],
data:function(){
    return {msg:this.textDisplay()}
},
 methods:{
    textDisplay(){
        return this.$emit('isAuth')?'Sign in with Microsoft':'Sign out from Microsoft'
    }
 }
}
</script>

parent component:

 insertBtnComponent){
    var ComponentClass = Vue.extend(buttonVue)
    var instance = new ComponentClass({
    propsData:{class:"buttonMs" ,style:" position: static ;",
    'action':this.isUserAuthenticated()?this.signOut():this.signInUser(),
    'isAuth':this.isUserAuthenticated()
   }
 })
  let selector = document.querySelector(".classNAMEofDiv");
  instance.$mount()
  selector.appendChild(instance.$el)

I would appreciate any hints on my problem, thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文