1
2
<component :is="c" >
</component>

通过component动态设置组件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${title}</title>
<meta name="decorator" content="single"/>
<script src="/static/common/js/vue.js"></script>

<link rel="stylesheet" href="https://unpkg.com/iview/dist/styles/iview.css">

<script type="text/javascript" src="/static/common/js/iview.min.js"></script>

</head>
<body>
<div id="app">
<component :is="c" >
</component>

<i-button @click="changeC('A')">A</i-button>
<i-button @click="changeC('B')">B</i-button>
<i-button @click="changeC('C')">C</i-button>

</div>



<script>


var app=new Vue({
el:"#app",
data:{
c:"comA",
},
components:{
"comA":{
template:"<div>comA content</div>"
},
"comB":{
template:"<div>comB content</div>"
},
"comC":{
template:"<div>comC content</div>"
},
},
methods:{
changeC:function(c){
this.c="com"+c;
},
},
computed:{

}
})
</script>
</body>

</html>