最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue指令v-for遍歷輸出JavaScript數(shù)組及json對象的常見方式小結(jié)

 更新時間:2019年02月11日 09:29:48   作者:Mosowe  
這篇文章主要介紹了Vue指令v-for遍歷輸出JavaScript數(shù)組及json對象的常見方式,結(jié)合實例形式總結(jié)分析了vue.js使用v-for指令遍歷輸出js數(shù)組與json對象的常見操作技巧,需要的朋友可以參考下

本文實例講述了Vue指令v-for遍歷輸出JavaScript數(shù)組及json對象的常見方式。分享給大家供大家參考,具體如下:

定義數(shù)據(jù):

<script>
  new Vue({
    el:"#test",
    data:{
      message:"infor",
      list:["a","b","c","d","e"],
      web:{
        "百度":"https://www.baidu.com",
        "搜狐":"https://www.sohu.com",
        "新浪":"https://www.sina.com",
        "淘寶":"https://www.taobao.com"
      }
    }
  })
</script>

html結(jié)構(gòu):

<div id="test">
    <div>{{ message }}</div>
    <div>{{ list }}</div>
    <div>{{ web }}</div>
</div>

完整示例:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>v-for遍歷</title>
</head>
<body>
  <div id="test">
    <div>{{ message }}</div>
    <div>{{ list }}</div>
    <div>{{ web }}</div>
  </div>
  <script src="https://cdn.bootcss.com/vue/2.4.4/vue.min.js"></script>
  <script>
    new Vue({
      el:"#test",
      data:{
        message:"infor",
        list:["a","b","c","d","e"],
        web:{
          "百度":"https://www.baidu.com",
          "搜狐":"https://www.sohu.com",
          "新浪":"https://www.sina.com",
          "淘寶":"https://www.taobao.com"
        }
      }
    })
  </script>
</body>
</html>

使用在線HTML/CSS/JavaScript代碼運行工具http://tools.jb51.net/code/HtmlJsRun冊數(shù),輸出結(jié)果:

v-for對數(shù)組的幾種輸出方式:

1.只輸出value值

html代碼:

<div id="test">
    <div v-for = "item in list">{{ item }}</div>
</div>

使用在線HTML/CSS/JavaScript代碼運行工具http://tools.jb51.net/code/HtmlJsRun冊數(shù),輸出結(jié)果:

2.輸出value值且輸出對應(yīng)的索引值

html代碼:

<div id="test">
    <div v-for = "(item,index) in list">{{ item }}的索引值是{{ index }}</div>
</div>

使用在線HTML/CSS/JavaScript代碼運行工具http://tools.jb51.net/code/HtmlJsRun冊數(shù),輸出結(jié)果:

v-for對json格式的幾種輸出方式

1.只輸出value值

html代碼:

<div id="test">
    <div v-for = "item in web">{{ item }}</div>
</div>

使用在線HTML/CSS/JavaScript代碼運行工具http://tools.jb51.net/code/HtmlJsRun冊數(shù),輸出結(jié)果:

2.輸出value值和key值

html代碼:

<div id="test">
    <div v-for = "(item,key) in web">{{ key }} 的網(wǎng)址是 : {{ item }}</div>
</div>

使用在線HTML/CSS/JavaScript代碼運行工具http://tools.jb51.net/code/HtmlJsRun冊數(shù),輸出結(jié)果:

3.輸出value值,key值和索引值index

html代碼:

<div id="test">
    <div v-for = "(item,key,index) in web">{{ index }}__{{ key }} 的網(wǎng)址是 : {{ item }}</div>
</div>

使用在線HTML/CSS/JavaScript代碼運行工具http://tools.jb51.net/code/HtmlJsRun冊數(shù),輸出結(jié)果:

可以看出,在數(shù)組里面,小括號里面的參數(shù)第一位是value值,第二位是索引值
在json里面,第一位是value值,第二位是key值,第三位是索引值

有的文章里面說$index是數(shù)組的內(nèi)置變量數(shù)組下標(biāo),$key是json內(nèi)置變量,可是我沒有測出來,且提示有錯,不知道這個到底對不對。

希望本文所述對大家vue.js程序設(shè)計有所幫助。

相關(guān)文章

最新評論

乌拉特后旗| 邹平县| 高台县| 盐山县| 南丹县| 宜兴市| 桂东县| 安康市| 疏勒县| 新巴尔虎右旗| 茶陵县| 河东区| 巴林右旗| 新安县| 榕江县| 大英县| 屏边| 双辽市| 太原市| 巴中市| 屏山县| 沅江市| 尉氏县| 行唐县| 平原县| 唐海县| 平南县| 孝昌县| 内黄县| 平安县| 策勒县| 沐川县| 安平县| 金湖县| 新丰县| 莆田市| 思茅市| 景德镇市| 赤壁市| 兴仁县| 大名县|