Vue.js 动态组件使用

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> 
</head>
<body>
<div id="app">	
	<span @click="coml('coma')">111111</span>
	<span @click="coml('comb')">2222</span>
	<span @click="coml('comc')">333333</span>
	<component :is="currentcom"></component>
</div>	

</body>
<script>
	 var vm = new Vue({
	  el: '#app',
	  data:{
		  currentcom:'coma'
	  },
	  methods:{
		  coml:function(e){
			  this.currentcom=e
		  }
	  },
	  components:{
		 coma:{
			  template:"<h1>11111</h1>"
		 },
		 comb: { 
		     template: "<div>222221</div>"  
		 },
		 comc:{
			  template: "<div>33333331</div>"  
		}
	 }

	})
</script>
</html>

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页