<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>引用模板</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<my-world></my-world>
</div>
<template id="wbs">
<div>
<h3>{{msg}}</h3>
<ul>
<li v-for="(item,index) in arr" :key="index">{{item}}</li>
</ul>
</div>
</template>
<script>
var vm = new Vue({ //这里的vm也是一个组件,称为根组件Root
el: '#app',
data: {
msg: '软谋'
},
components: {
'my-world': {
name: 'wbsx',
template: '#wbs',
data() {
return {
age: '20',
msg: 'hello',
arr: ['tom', 'jack', 'laney']
}
}
}
}
});
</script>
</body>
</html>
模板template的使用
最新推荐文章于 2022-02-06 18:39:57 发布