<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>组件</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<script src="../js/Vue.js"></script>
<script type="x-template" id="aaa">
<h2 @click="change">标题->{{msg}}</h2>
</script>
<script>
window.onload = function(){
var vm = new Vue({
el:'#box',
components:{
aaa:{
data(){
return {
msg:'welcome vue'
}
},
methods:{
change(){
this.msg = 'changed';
}
},
template:'#aaa'
}
}
});
}
</script>
</head>
<body>
<div id="box">
<aaa></aaa>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>组件</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<script src="../js/vue1.0.js"></script>
</head>
<body>
<div id="box">
<my-aaa></my-aaa>
</div>
<template id="aaa">
<h2>标题</h2>
<ul>
<li v-for="val in arr">{{val}}</li>
</ul>
</template>
<script>
var vm = new Vue({
el:'#box',
components:{
'my-aaa':{
data(){
return {
msg:'welcome vue',
arr:['apple','banana','orange']
}
},
methods:{
change(){
this.msg = 'changed';
}
},
template:'#aaa'
}
}
});
</script>
</body>
</html>