Is there way to inherit templates with mixins in VueJS

后端 未结 2 1171
北恋
北恋 2020-12-31 08:04

Someone knows how inherit a mixin with its template? or how to inject dinamically elements or components from a mixin?

EDIT:

2条回答
  •  礼貌的吻别
    2020-12-31 08:42

    You can't "inherit" mixin templates like in your example, if it were possible there would have to be a standardized way of merging the templates.

    Since it seems all you really want to do is inherit the template, why not use component composition with slots?

    Vue.component('not-found', {
      template: '#not-found',
      methods: {
        doSomethingSpecial() {
          alert('Hi there');
        },
      },
    });
    
    new Vue({
      el: '#app',
      data() {
        return {
          notFoundVisible: false,
        };
      },
    });
    .not-found {
      background-color: white;
      text-align: center;
      font-size: 30px;
      position: fixed;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
    }
    
    
    
    
    
    The resource was not found

    Is there any particular reason why you need to mixin these components instead of composing them together?

提交回复
热议问题