分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

vue.js学习日记-组件篇

发布时间:2023-09-06 01:12责任编辑:郭大石关键词:js组件

组件

自定义组件 全局注册

var question={name:‘MR Liu‘}

Vue.component(‘my-header‘,{

template:‘<p>hello world{{name}}</p>

‘,

data:function(){//data必须是函数 且一般只能返回一个对象

return question//没有‘;’这个结束符

}

})

注意 question和template之间的关系一定要自己明确

局部注册:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Demo</title>
<script src="https://unpkg.com/vue"></script>
</head>
<body>
<div id="app">
?<two></two>
</div>

<script type="text/javascript">
var ask={age:25}
var three={
?template:‘<h1>我是第THREE</h1>‘,

data:function(){

return ask;}
}//这个结尾这里没有‘,’号,因为这个是在,一个对象外部,不需要语句分割符
var two={
?template:‘<p><three></three>我是第TWO{{age}}</p>‘,
?components:{
???‘three‘:three
?}
}
var vm=new Vue({
?el:‘#app‘,
?data:{
???holidary:‘WELCOME COME TO 自定义组件‘
?},
?components:{//el所挂0载 的元素是根元素,<two><two>只能在<div id=‘app‘><div>之内有效

‘two‘:two
?}
})
</script>
</body>
</html>

props自定义属性props[‘hello‘] 不能使用v-bind:hello=‘X‘ 只能使用hello=‘x‘

vue.js学习日记-组件篇

原文地址:http://www.cnblogs.com/LiuCaoMei/p/7545642.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved