亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

VUE的tab頁(yè)面切換的四種方法

 更新時(shí)間:2021年04月25日 14:15:14   作者:淺淺一笑^*^  
這篇文章主要介紹了VUE的tab頁(yè)面切換的四種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

1.靜態(tài)實(shí)現(xiàn)方法:

效果圖:

在這里插入圖片描述

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>view的tab交互</title>
  <link rel="stylesheet" href="../css/demo.css" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >
</head>
<body>
<div class="demo_warp" id="my">
<ul class="tab_tit">
  <li :class="n==1?'active':''" @click="n=1">標(biāo)題一</li>
  <li :class="n==2?'active':''" @click="n=2">標(biāo)題二</li>
  <li :class="n==3?'active':''" @click="n=3">標(biāo)題三</li>
  <li :class="n==4?'active':''" @click="n=4">標(biāo)題四</li>
</ul>
<!-- neirong -->
<div class="tab_con">
  <div v-show="n==1">內(nèi)容一</div>
  <div v-show="n==2">內(nèi)容二</div>
  <div v-show="n==3">內(nèi)容三</div>
  <div v-show="n==4">內(nèi)容四</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script> Vue.config.productionTip=false </script>  
<script src="../js/tab.js" type="text/javascript"></script>
</body>
</html>

css

*{
  margin: 0;
  padding: 0;
  box-sizing:border-box;
}
body,html{
 height: 100%;
}
.demo_warp .tab_tit {
  display: flex;
  flex: 1;
  margin:.2rem;
}
.demo_warp .active { 
  color:red;
  background-color: cadetblue;
}
.demo_warp ul li {
  list-style: none;
  width: 23%;
  text-align: center;
  background-color: #ccc;
  margin:0 1%;
}
.demo_warp .tab_con {
  width: 100%;
  height: 3rem;
  border:1px solid rgb(85, 85, 177);
  text-align: center;
}

js

window.onload=function(){
  new Vue({
    el:'#my',
      data:{//響應(yīng)式的數(shù)據(jù) data變化頁(yè)面也會(huì)跟著變化
     n:1
    }
  })

}

2.第二種模擬動(dòng)態(tài)方法

效果如上圖所示:(省略)
代碼:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>view的tab交互</title>
  <link rel="stylesheet" href="../css/demo.css" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >
</head>
<body>
<div class="demo_warp" id="my">
<ul class="tab_tit">
  <li v-for="(v,i) in title" :class="n==i?'active':''" @click="n=i">{{v}}</li>
</ul>
<!-- neirong -->
<div class="tab_con">
  <div v-for="(v,i) in con" v-show="n==i">{{v}}</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script> Vue.config.productionTip=false </script>  
<script src="../js/tab.js" type="text/javascript"></script>
</body>
</html>

css

*{
  margin: 0;
  padding: 0;
  box-sizing:border-box;
}
body,html{
 height: 100%;
}
.demo_warp .tab_tit {
  display: flex;
  flex: 1;
  margin:.2rem;
}
.demo_warp .active { 
  color:red;
  background-color: cadetblue;
}
.demo_warp ul li {
  list-style: none;
  width: 23%;
  text-align: center;
  background-color: #ccc;
  margin:0 1%;
}
.demo_warp .tab_con {
  width: 100%;
  height: 3rem;
  border:1px solid rgb(85, 85, 177);
  text-align: center;
}

js

window.onload=function(){
  new Vue({
    el:'#my',
      data:{//響應(yīng)式的數(shù)據(jù) data變化頁(yè)面也會(huì)跟著變化
     n:0,
     title:["標(biāo)題一","標(biāo)題二","標(biāo)題三","標(biāo)題四"],
     con:["內(nèi)容一","內(nèi)容二","內(nèi)容三","內(nèi)容四"]
    }
  })
}

3.第三種動(dòng)態(tài)數(shù)據(jù)方法

效果圖:(滾動(dòng)條的實(shí)現(xiàn)方式)

在這里插入圖片描述

代碼:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>view的tab交互</title>
  <link rel="stylesheet" href="../css/demo.css" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >
</head>
<body>
<div class="demo_warp" id="my">
<ul class="tab_tit">
  <li v-for="(v,i) in lists" :class="n==i?'active':''" @click="n=i">{{v.title}}</li>
</ul>
<!-- neirong -->
<div class="tab_con">
  <div v-for="(v,i) in lists" v-show="n==i">{{v.con}}</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script> Vue.config.productionTip=false </script>  
<script src="../js/tab.js" type="text/javascript"></script>
</body>
</html>

css

*{
  margin: 0;
  padding: 0;
  box-sizing:border-box;
}
body,html{
 height: 100%;
}
.demo_warp .tab_tit{
  display: flex;
  justify-content: space-between;
  white-space: nowrap;
  overflow-y: hidden;
  overflow-x: scroll; 
   margin:1% 1% 1% 0;
}
  ::-webkit-scrollbar{
   display: none;
  }
.demo_warp .active { 
  color:red;
  background-color: cadetblue;
}
.demo_warp ul li {
  list-style: none;
  padding:1.2% 3.2%;
  text-align: center;
  background-color: #ccc;
  margin-left: 1%;
}
.demo_warp .tab_con {
  width: 100%;
  height: 3rem;
  border:1px solid rgb(85, 85, 177);
  text-align: center;
}

js

window.onload=function(){
  new Vue({
    el:'#my',
      data:{//響應(yīng)式的數(shù)據(jù) data變化頁(yè)面也會(huì)跟著變化
     n:0,
     lists:[//可以有很多條數(shù)據(jù)//數(shù)組對(duì)象的形式
       {title:'標(biāo)題一',con:'內(nèi)容一'},
       {title:'標(biāo)題二',con:'內(nèi)容二'},
       {title:'標(biāo)題三',con:'內(nèi)容三'},
       {title:'標(biāo)題四',con:'內(nèi)容四'},
       {title:'標(biāo)題五',con:'內(nèi)容五'},
       {title:'標(biāo)題六',con:'內(nèi)容六'},
       {title:'標(biāo)題七',con:'內(nèi)容七'},
       {title:'標(biāo)題八',con:'內(nèi)容八'},
     ]
    }
  })
}

4.動(dòng)態(tài)實(shí)現(xiàn)方法(模擬后臺(tái)數(shù)據(jù)實(shí)現(xiàn))

效果圖:

在這里插入圖片描述

代碼:

<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>view的tab交互</title>
  <link rel="stylesheet" type="text/css" href="../css/demo.css" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >
</head>
<body>
<div class="demo_warp" id="my">
  <ul class="tab_tit">
    <li v-for="(v,i) in lists" :class="m==i?'active':''" @click="m=i" :key="i.title">{{v.title}}</li>
  </ul>
  <!-- neirong -->
  <div class="tab_con">
    <div v-for="(v,i) in lists" v-show="m==i" :key="i.con">{{v.con}}</div>
  </div>
  <!-- -----------動(dòng)態(tài)數(shù)據(jù)----------- -->
<ul class="tab_tit">
  <li v-for="(item, index) in itemList" :class="n==index?'active':''" @click="n=index" :key="index">{{item.name}}</li>
</ul>
<!-- neirong -->
<div class="tab_con">
  <div v-for="(item, index) in itemList" v-show="n==index" :key="index">{{item.state}}</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script> Vue.config.productionTip=false </script>  
<script src="../node_modules/axios/dist/axios.js"></script>
<script src="../js/tab.js" type="text/javascript"></script>
</body>
</html>

css

*{
  margin: 0;
  padding: 0;
  box-sizing:border-box;
}
body,html{
 height: 100%;
}
.demo_warp .tab_tit{
  display: flex;
  justify-content: space-between;
  white-space: nowrap;
  overflow-y: hidden;
  overflow-x: scroll; 
   margin:1% 1% 1% 0;
}
  ::-webkit-scrollbar{
   display: none;
  }
.demo_warp .active { 
  color:red;
  background-color: cadetblue;
}
.demo_warp ul li {
  list-style: none;
  padding:1.2% 3.2%;
  text-align: center;
  background-color: #ccc;
  margin-left: 1%;
}
.demo_warp .tab_con {
  width: 100%;
  height: 3rem;
  border:1px solid rgb(85, 85, 177);
  text-align: center;
}

tab.js

window.onload=function(){
  new Vue({
    el:'#my',
      data(){//響應(yīng)式的數(shù)據(jù) data變化頁(yè)面也會(huì)跟著變化
       return{
          n:0,
          m:0,
         lists:[
       {title:'標(biāo)題一',con:'內(nèi)容一'},
       {title:'標(biāo)題二',con:'內(nèi)容二'},
       {title:'標(biāo)題三',con:'內(nèi)容三'},
       {title:'標(biāo)題四',con:'內(nèi)容四'},
       {title:'標(biāo)題五',con:'內(nèi)容五'},
       {title:'標(biāo)題六',con:'內(nèi)容六'},
       {title:'標(biāo)題七',con:'內(nèi)容七'},
       {title:'標(biāo)題八',con:'內(nèi)容八'},
       ], 
        itemList:[]
       }
     },
    methods:{
      getList:function(){//this:--【函數(shù)和定時(shí)器的this指向都是window (而我們是要this指向vue實(shí)例)】
        var that=this;//局部定義改變this指向
        //每執(zhí)行此方法,提前清空數(shù)組,保證往下執(zhí)行代碼,數(shù)組為空
        // this.itemList = [];
        axios({
          method:'get',
          url:'http://localhost:4000/list'
        }).then(function(res){
            console.log(res);
            that.itemList = res.data.result;
        }).catch(function(error){
           console.log(error);
        })
      }
    },
    mounted:function(){
         this.getList();
    },
  })
}

nodeServer.js

 /*
  connect 是一個(gè)node中間件 (middeware)框架
  如果把一個(gè)http處理過(guò)程比作是污水處理 中間件就像是一層層的過(guò)濾網(wǎng)
  每個(gè)中間件把http處理過(guò)程中通過(guò)改寫 request或(和)response的數(shù)據(jù)、狀態(tài)、實(shí)現(xiàn)了特定的功能
  中間件就是類似于一個(gè)過(guò)濾器的東西 在客戶端和應(yīng)用程序之間的一個(gè)處理請(qǐng)求和響應(yīng)的方法.
 */

//創(chuàng)建中間介 啟動(dòng)服務(wù) node node.js  
var connect = require('connect');//創(chuàng)建連接
var bodyParser=require('body-parser');//body解析 用于處理 JSON、RAW、Text和URL編碼的數(shù)據(jù).
var lists = {};
var app = connect()
    .use(bodyParser.json())//JSON解析
    .use(bodyParser.urlencoded({extended:true}))
   //use()方法還有一個(gè)可選的路徑字符串 對(duì)傳入請(qǐng)求的URL的開始匹配
   //use()方法來(lái)維護(hù)一個(gè)中間件隊(duì)列
   .use(function(req,res,next){
    //跨域處理
    //website you wish to allow to connect
    res.setHeader('Access-Control-Allow-origin','*');//允許任何源
    //Request Methods you width to allow
    res.setHeader('Access-Control-Allow-Methods','CET','POST','OPTIONS','PUT','PATCH','DELETE');//允許任何方法
    //Request headers you wish to allow
    res.setHeader('Access-Control-Allow-Headers','*');//允許任何類型
    res.writeHead(200,{"Content-Type":"text/plain/xml;charset=utf-8"});//utf-8轉(zhuǎn)碼
    next();//next方法就是一個(gè)遞歸調(diào)用
   })
   .use('/list',function(req,res,next){
     var data={
       "code":"200",
       "msg":"success",
       "result":[
         {name:"手機(jī)",state:"采購(gòu)一"},
         {name:"包包",state:"采購(gòu)二"},
         {name:"衣服",state:"采購(gòu)三"},
         {name:"電腦",state:"采購(gòu)四"},
         {name:"電子產(chǎn)品",state:"采購(gòu)五"}
      ]
     }
     res.end(JSON.stringify(data));
     next();
   })
   .use('/list_get',function(req,res,next){
    var data={
      "code":'200',
      "msg":"success",
      "result":lists
    }
    res.end(JSON.stringify(data));
    next();
   })
   .use('/list_add',function(req,res,next){
     if(req.method=='POST'){
       console.log(req.body.name);
       lists.push({name:req.body.name,state:req.body.state,id:index++});
       var data={"code":200,"msg":"success"};
       res.end(JSON.stringify(data));
     }else{
       res.end(JSON.stringify({}));
     }
     next();
   })
   .use('/list_del',function(req,res,next){
    console.log(req.body.id);
    //lists=lists.filter(list=>list.id!=req.body.id);
    for(var i=0;i<lists.length;i++){
      if(req.body.id===lists[i].id){
            lists.splice(i,1);
      }
    }
    console.log(lists);
    var data={"code":200,"msg":"success"};
    res.end(JSON.stringify(data));
    next();
   })
   .listen(4000);
   console.log('Server started on port 4000.');

插件:(需要下載的插件)

在這里插入圖片描述

1.先啟動(dòng)服務(wù)node nodeServer.js(不能關(guān)閉,否則就會(huì)調(diào)取不到數(shù)據(jù))
2.之后運(yùn)行html頁(yè)面 。

項(xiàng)目遇到的bug:

vue中v-for循環(huán)遍歷后,當(dāng)前內(nèi)容不渲染的問(wèn)題,因?yàn)閠his指向的問(wèn)題導(dǎo)致.

解決方法一:

在這里插入圖片描述

解決方法二:

在這里插入圖片描述

解決方法三:

在這里插入圖片描述

總結(jié):url:接口要寫自己后臺(tái)的接口哦,這里只是模擬的接口,nodeServer.js文件可以定義多種格式的數(shù)據(jù)類型,也可以在本地自定義嵌套多種需要的類型,先試用之后可以在調(diào)后臺(tái)數(shù)據(jù)。

推薦學(xué)習(xí)VUE:文檔 ::https://cn.vuejs.org/v2/guide/list.html

到此這篇關(guān)于VUE的tab頁(yè)面切換的四種方法的文章就介紹到這了,更多相關(guān)VUE tab頁(yè)面切換內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 使用vue打包時(shí)vendor文件過(guò)大或者是app.js文件很大的問(wèn)題

    使用vue打包時(shí)vendor文件過(guò)大或者是app.js文件很大的問(wèn)題

    這篇文章主要介紹了使用vue打包時(shí)vendor文件過(guò)大或者是app.js文件很大問(wèn)題的解決方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-06-06
  • Vue插槽的作用

    Vue插槽的作用

    插槽(slot)是 vue 為組件的封裝者提供的能力。允許開發(fā)者在封裝組件時(shí),把不確定的、希望由用戶指定的部分定義為插槽??梢园巡宀壅J(rèn)為是組件封裝期間,為用戶預(yù)留的內(nèi)容的占位符
    2022-09-09
  • Vue之關(guān)于Eslint自動(dòng)加分號(hào)的問(wèn)題及解決

    Vue之關(guān)于Eslint自動(dòng)加分號(hào)的問(wèn)題及解決

    這篇文章主要介紹了Vue之關(guān)于Eslint自動(dòng)加分號(hào)的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • vue2老項(xiàng)目vite升級(jí)改造過(guò)程記錄

    vue2老項(xiàng)目vite升級(jí)改造過(guò)程記錄

    目前vite主要默認(rèn)是支持給vue3使用的,并且如果使用官方的cli創(chuàng)建的項(xiàng)目一樣會(huì)默認(rèn)使用vue3去構(gòu)建項(xiàng)目,此時(shí)對(duì)于一些vue2的老項(xiàng)目就顯得不友好了,下面這篇文章主要給大家介紹了關(guān)于vue2老項(xiàng)目vite升級(jí)改造的相關(guān)資料,需要的朋友可以參考下
    2022-12-12
  • Vue學(xué)習(xí)筆記之跨域的6種解決方案

    Vue學(xué)習(xí)筆記之跨域的6種解決方案

    在前后端分離項(xiàng)目中,跨域是一定會(huì)出現(xiàn)的問(wèn)題,下面這篇文章主要給大家介紹了關(guān)于Vue學(xué)習(xí)筆記之跨域的6種解決方案,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-04-04
  • 如何使用RoughViz可視化Vue.js中的草繪圖表

    如何使用RoughViz可視化Vue.js中的草繪圖表

    這篇文章主要介紹了如何使用RoughViz可視化Vue.js中的草繪圖表,幫助大家更好的理解和使用roughViz,感興趣的朋友可以了解下
    2021-01-01
  • vue el-checkbox實(shí)現(xiàn)全選單選方式

    vue el-checkbox實(shí)現(xiàn)全選單選方式

    這篇文章主要介紹了vue el-checkbox實(shí)現(xiàn)全選單選方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • Vue組件庫(kù)發(fā)布到npm詳解

    Vue組件庫(kù)發(fā)布到npm詳解

    本片文章給大家詳細(xì)介紹了如何將Vue組件庫(kù)發(fā)布到npm的方法以及代碼示例分享,感興趣的朋友參考學(xué)習(xí)下。
    2018-02-02
  • Vue3(ts)使用vee-validate表單校驗(yàn),自定義全局驗(yàn)證規(guī)則說(shuō)明

    Vue3(ts)使用vee-validate表單校驗(yàn),自定義全局驗(yàn)證規(guī)則說(shuō)明

    這篇文章主要介紹了Vue3(ts)使用vee-validate表單校驗(yàn),自定義全局驗(yàn)證規(guī)則說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • Vue組件間的通信方式詳析

    Vue組件間的通信方式詳析

    本文介紹Vue組件間通信方式,Vue組件間通信一直是個(gè)重要的話題,雖然官方推出的Vuex狀態(tài)管理方案可以很好的解決組件之間的通信問(wèn)題,但是在組件庫(kù)內(nèi)部使用Vuex往往會(huì)比較重,本文將系統(tǒng)的羅列出幾種不使用Vuex,比較實(shí)用的組件間的通信方式,希望能幫助到大家
    2022-09-09

最新評(píng)論