<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
<button onclick="load">动态加载组件</button>
<component v-bind:is="currentTabComponent" :message="message"></component>
</div>
<script>
// 注册
Vue.component('child', {
// 声明 props
props: ['message'],
// 同样也可以在 vm 实例中像 “this.message” 这样使用
template: '<span>{
{ message }}</span>'
})
// 创建根实例
new Vue({
data:function(){
return {
currentTabComponent:null,
message:'hello!'
}
},
methods:{
load:function(){
this.$currentTabComponent = 'child&
vue动态加载组件通过 Prop 向子组件传递数据
最新推荐文章于 2024-06-09 11:42:38 发布