vue 混合

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="traceur.js"></script>
    <script src="BrowserSystem.js"></script>
    <script src="bootstrap.js"></script>
    <script src="vue.js"></script>
</head>

<script type="text/traceur">
    // 定义一个混合对象
    var myMixin = {
      created: function () {
        this.hello()
      },
      methods: {
        hello: function () {
          console.log('hello from mixin!')
        }
      },
      render: function (createElement) {
        return createElement(
          'h' + this.level,   
          this.$slots.default
        )
      },
      //template:'<h3>我是标题33</h3>',
    }
    // 定义一个使用混合对象的组件
    var Component = Vue.extend({
      mixins: [myMixin],
      //template:'<h3>我是标题55</h3>'
    });
    //var component = new Component({
        //template:'<h3>我是标题55</h3>',
    //}) // -> "hello from mixin!"
    Vue.component('aaa',Component);
    /*new Vue({
      el: '#demo',
    });*/
</script>

<body>

    <div id="demo">
        <aaa>renderrender</aaa>
    </div>
    
</body>
</html>
原文地址:https://www.cnblogs.com/yaowen/p/7121194.html