ç»ä»¶
程序员文章站
2022-06-06 19:54:53
...
模ååæ¯ä»ä»£ç é»è¾è§åº¦ååçä¿è¯åè½æ¨¡åèè½åä¸ï¼ç»ä»¶åæ¯ä»uiçé¢ååçæ¹ä¾¿uiç»ä»¶éç¨
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<h3 id="h3">
{{msg}}
</h3>
<!-- <my-com1></my-com1> -->
<!-- <mycom2></mycom2> -->
<mycom3></mycom3>
<login></login>
<input type="button" value="x" @click="msg='no'">
</div>
<!-- #appå¤ï¼å®ä¹ç»ä»¶æ¨¡æ¿ç»æ #tmp1 -->
<template id="tmp1">
<div>
<h1>
å
¨å±mycom3ç»ä»¶{{msg}}
</h1>
</div>
</template>
<template id = "tmp2">
<div>
ç§æ
</div>
</template>
<script>
// var com1 = Vue.extend({
// template: '<h3>ç»ä»¶</h3>'
// })
// Vue.component('myCom1', com1)
// Vue.component('myCom1', Vue.extend({
// template: '<h3>ç»ä»¶</h3>'
// }))
// Vue.component('mycom2', {
// template: '<h3>com2ç»ä»¶</h3>'
// })
Vue.component('mycom3', {
template: '#tmp1',
data:function(){
return {
msg: 'ç»ä»¶èªå·±çæ°æ®'
}
}
})
new Vue({
el: '#app',
data: {
name: '',
msg: new Date()
},
methods: {
add() {
console.log('ok')
}
},
components: {
login: {
template: '#tmp2'
}
}
})
</script>
</body>
</html>
ç»ä»¶åæ¢
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<a href="" @click.prevent="flag=true">ç»å½</a>
<a href="" @click.prevent="flag=false">注å</a>
<login v-if="flag"></login>
<register v-else="flag"></register>
</div>
<script>
// ç»ä»¶åæ¢
Vue.component('login',{
template: '<h3>ç»å½ç»ä»¶</h3>'
})
Vue.component('register',{
template: '<h3>注åç»ä»¶</h3>'
})
new Vue({
el: '#app',
data: {
flag: true,
msg: new Date()
},
methods: {
add() {
console.log('ok')
}
}
})
</script>
</body>
</html>