1 Star 0 Fork 0

prcool/前端开发学习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
组件3-组件切换.html 2.48 KB
一键复制 编辑 原始数据 按行查看 历史
prcool 提交于 2021-09-11 21:02 +08:00 . 前端开发学习
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<!-- 引入vue.js -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<h1>{{msg}}</h1>
<a href="" @click.prevent="flag=true">登录</a>
<a href="" @click.prevent="flag=false">注册</a>
<login v-if="flag"></login>
<register v-else="flag"></register>
<a href="" @click.prevent="comName='login'">login</a>
<a href="" @click.prevent="comName='register'">register</a>
<component :is="comName"></component>
<!--动态组件-->
<button v-for="tab in tabs" :key="tab" @click="currentTabComponent=tab">{{tab}}</button>
<component :is="currentTabComponent"></component>
</div>
</body>
<template id="temp1">
<div>
<h1>登录组件</h1>
</div>
</template>
<template id="temp2">
<div>
<h1>注册组件</h1>
</div>
</template>
<template id="aa">
<div>
<h1>aa</h1>
</div>
</template>
<template id="bb">
<div>
<h1>bb</h1>
</div>
</template>
<template id="cc">
<div>
<h1>cc</h1>
</div>
</template>
<script>
const aa = {
template:'#aa',
}
const bb = {
template:'#bb',
}
const cc = {
template:'#cc',
}
// 实例化vue对象
let vm = new Vue({
// 绑定对象
el:'#app',
data:{
msg:'hello vue.js',
flag:false,
comName:'login',
tabs:['aa','bb','cc'],
currentTabComponent:'aa'
},
methods:{
},
components:{
login:{
template:'#temp1',
data:function(){
return{
}
},
methods:{
}
},
register:{
template:'#temp2',
data:function(){
return{
}
},
methods:{
}
},
aa,bb,cc
}
})
</script>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/prcool/front-end-development-learning.git
git@gitee.com:prcool/front-end-development-learning.git
prcool
front-end-development-learning
前端开发学习
master

搜索帮助