vue组件
作者:互联网
Vue组件
组件是可复用的 Vue 实例,且带有一个名字
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!--view层模板,组件就是模板的意思-->
<div id="app">
<shiyi></shiyi>
</div>
<!--1.导入vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
<script>
//定义一个vue组件component
Vue.component("shiyi",{
template:'<li>Hello</li>'
//<li> ,是前面有小黑点
});
var vm = new Vue({
el: "#app"
});
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!--view层模板,组件就是模板的意思-->
<div id="app">
<shiyi v-for="item in items" v-bind:qin="item"></shiyi>
<!--v-bind:遍历的参数="接收参数"-->
</div>
<!--1.导入vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
<script>
//定义一个vue组件component
Vue.component("shiyi",{
props: ['qin'],
template:'<li>{{qin}}</li>'
//<li> ,是前面有小黑点
});
//说下这两是同级,需要中间商赚差价
var vm = new Vue({
el: "#app",
data: {
items: ["java","前端","后端"]
}
});
</script>
</body>
</html>
这就是套娃!
标签:el,vue,component,Vue,组件,qin 来源: https://www.cnblogs.com/shiyi1/p/16538876.html