其他分享
首页 > 其他分享> > vue-组件0.1

vue-组件0.1

作者:互联网

组件

组件的使用步骤

组件分类

Vue.component("my-extend",{
            template:`  
          <div>
                <div>我是组件</div>
                <div>{{msg}}</div>
            </div>`,
            data(){
              return {
                  msg:'这是msg'
              }
          }
        })
var myextend = Vue.extend({
          template:`  
          <div>
                <div>我是组件</div>
                <div>{{msg}}</div>
            </div>         `,  //外面用一个div包裹起来,不然可能会报错
          data(){
              return {
                  msg:'这是msg'
              }
          }
      })
      var vm = new Vue({
          el:"#root",
          data:{
              
          },
          components:{
              "my-extend":myextend
          }
      })

注意

使用构造器

 var myCpn = Vue.extend({
            template: `
             <div>
                <h1>这是用构造器写的组件</h1>
            </div>
            `
        })

语法糖

Vue.component('myYft',{
            template: `
             <div>
                <h1>这是用语法糖写的组件</h1>
            </div>
            `
        })
var myCom = {
            template: `
             <div>
                <h1>这是用创建组件对象写的组件</h1>
            </div>
            `
        }

template

<template id="sons">
        <div>
            <p>{{msg}}</p>
            <button @click="change">加</button>
        </div>
    </template>
​
    <script>
        var son ={
            template:"#sons",
            data(){
                return {
                    msg:0
                }
            }}
            ...
    </script>       

组件传值

标签:vue,extend,0.1,var,msg,Vue,template,组件
来源: https://blog.csdn.net/weixin_51197518/article/details/122462670