vuejs 组件的认识

来源:互联网 发布:看韩国电影软件 编辑:程序博客网 时间:2024/05/16 03:06

vuejs 组件分为:全局注册组件和局部注册组件,我称为全局组件和局部组件

全局组件:Vue.commonpent(‘组件名’,{       //组件名规范:小写,且用‘-’连接

template:'<div>html内容</div>',

data(){

return {

msg:'数据',

return msg

}

}

})


局部组件:局部组件注册在vue实例中,用components包括,具体示例如下

var app=new Vue({

el:'#app',

data:{},

components:{

v-header:header,

v-tabs:tabs,

v-content:contents

}

});


定义的这三个组件的方法:

一、var header={

template:'<div>内容</div>'

}

二、写到vue文件中 并引用

import header from ./header/header.vue

import tabs from ./tabs/tabs.vue

import content from ./content/content.vue

vue文件的格式

<template></template><script type="text/ecmascript-6">    export default {}</script><style lang="stylus" rel="stylesheet/stylus"></style>


原创粉丝点击