
没用<component>之前,切换组件要用which这个中间状态:
"which===home"> - <list v-show="which===home">list>
- <shopcar v-show="which===home">shopcar>
- <div id="box">
-
- <home v-show="which===home">home>
- <list v-show="which===home">list>
- <shopcar v-show="which===home">shopcar>
-
- <footer>
- <ul>
- <li @click="which='home'">
- 首页
- li>
- <li @click="which='list'">
- 列表
- li>
- <li @click="which='shopcar'">
- 购物车
- li>
- ul>
- footer>
- div>
- <script>
- Vue.component("home",{
- template:`
- home`
- })
-
- Vue.component("list",{
- template:`
- list`
- })
-
- Vue.component("shopcar",{
- template:`
- shopcar`
- })
-
-
- new Vue({
- el:"#box",
- data:{
- which:"home"
- },
- methods:{
-
- }
- })
- script>
用
- DOCTYPE html>
-
-
-
-
Document -
-
- *{
- margin: 0;
- padding: 0;
- }
- html,body{
- width:100% ;
- height: 100%;
- }
- ul{
- display: flex;
- list-style: none;
- position: fixed;
- left: 0px;
- bottom: 0px;
- width: 100%;
- }
- li{
- height: 50px;
- flex: 1;
- background-color: gray;
- color: white;
- text-align: center;
- line-height: 50px;
- border: 1px solid black;
- }
-
-
-
-
-
-
- 首页
-
-
- 列表
-
-
- 购物车
-
-
-
-
-
- Vue.component("home",{
- template:`
- home`
- })
-
- Vue.component("list",{
- template:`
- list`
- })
-
- Vue.component("shopcar",{
- template:`
- shopcar`
- })
-
-
- new Vue({
- el:"#box",
- data:{
- which:"home"
- },
- methods:{
-
- }
- })
-
效果:
