console
Vue.config.productionTip = false;
Vue.config.devtools = false;
const optionsA = {
render: (h) => h('span', '我是options - 父'),
};
const optionsB = {
render: (h) => h('span', '我是options - 子'),
};
const App = Vue.extend({
template: `<div>
当前组件: {{name}}
<br/>
<component :is="node" />
</div>`,
data() {
return {
name: 'App',
node: optionsA,
}
}
});
const Child = App.extend({
name: 'Child',
data() {
return {
name: 'Child',
node: optionsB,
}
}
});
const vm = new Vue({
el: '#app',
data() {
return {
isSuper: true,
};
},
components: { App, Child },
render(h) {
const that = this;
return h('div', {}, [
h('button', {
on: {
click: () => {
this.isSuper = true;
}
},
}, '父类'),
h('button', {
on: {
click: () => {
this.isSuper = false;
}
},
}, '子类'),
h(this.isSuper ? 'App' : 'Child')
]);
},
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>动态node测试</title>
</head>
<style>
body {
text-align: center;
}
</style>
<body>
<script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.min.js"></script>
<h3>动态node测试</h3>
<div id="app">
</div>
</body>
</html>