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

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

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

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

定義數(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代碼運(yùn)行工具http://tools.jb51.net/code/HtmlJsRun冊(cè)數(shù),輸出結(jié)果:

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

1.只輸出value值

html代碼:

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

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

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

html代碼:

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

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

v-for對(duì)json格式的幾種輸出方式

1.只輸出value值

html代碼:

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

使用在線HTML/CSS/JavaScript代碼運(yùn)行工具http://tools.jb51.net/code/HtmlJsRun冊(cè)數(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代碼運(yùn)行工具http://tools.jb51.net/code/HtmlJsRun冊(cè)數(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代碼運(yùn)行工具http://tools.jb51.net/code/HtmlJsRun冊(cè)數(shù),輸出結(jié)果:

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

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

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

相關(guān)文章

最新評(píng)論

武威市| 南澳县| 兴和县| 郯城县| 宕昌县| 竹溪县| 大石桥市| 昌平区| 淅川县| 廊坊市| 贺州市| 甘肃省| 玛多县| 浏阳市| 格尔木市| 巫山县| 射阳县| 普宁市| 宁国市| 陆丰市| 金秀| 申扎县| 确山县| 洞口县| 虎林市| 景泰县| 水富县| 仁寿县| 宁晋县| 丘北县| 丹巴县| 吉水县| 枣强县| 繁昌县| 天柱县| 新野县| 华宁县| 射阳县| 从化市| 弥勒县| 天峻县|