vue.js基础__ propsData 选项

首先写一个扩展 ,头部标签

然后再script中声明一个对象,对象中有一个模板

需要挂载扩展,然后磁能生效

propsData 主要用于传值,在扩展里需要接收,需用 props接收

具体代码如下:

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>propsData option</title>
<script src="../assets/js/vue.js"></script>
</head>

<body>
<h1>propsData option</h1>
<hr>
<header></header>

<script>
var header_a = Vue.extend({
template: `<p>{{ message }}-{{ a }}</p>`,
data() {
return {
message: 'hello'
}
},
props: ['a']
})

new header_a({ propsData: { a: 12 } }).$mount('header')
</script>
</body>

</html>
 

猜你喜欢

转载自www.cnblogs.com/sunyang-001/p/11103904.html
今日推荐