<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>全局组件及传值</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.js"></script>
</head>
<body>
<div id="app">
<my-component msg="我是第一个组件"></my-component>
</div>
<div id="app2">
<my-component msg="我是第二个组件"></my-component>
</div>
<script>
Vue.component('my-component',{
template:'<h1>{{msg}}</h1>',
props: {
msg: {
type: String,
default: '我是组件'
}
}
});
new Vue({
el: '#app',
})
new Vue({
el: '#app2',
})
</script>
</body>
</html>
Vue全局组件及传值
最新推荐文章于 2024-07-27 07:15:00 发布