当前位置:   article > 正文

vue 遍历嵌套数组_vue 两个数组一起遍历

vue 两个数组一起遍历

json

  1. {
  2. "user": [
  3. {
  4. "id": 1001,
  5. "name": "aaaa",
  6. "like": [
  7. {
  8. "num": 1,
  9. "cat": "evoke"
  10. }
  11. ]
  12. },
  13. {
  14. "id": 1002,
  15. "name": "bbbb",
  16. "like": [
  17. {
  18. "num": 2,
  19. "cat": "invoke"
  20. }
  21. ]
  22. },
  23. {
  24. "id": 1003,
  25. "name": "cccc",
  26. "like": [
  27. {
  28. "num": 3,
  29. "cat": "revoke"
  30. }
  31. ]
  32. },
  33. {
  34. "id": 1004,
  35. "name": "dddd",
  36. "like": [
  37. {
  38. "num": 4,
  39. "cat": "rocket"
  40. }
  41. ]
  42. }
  43. ]
  44. }

html

  1. <body>
  2. <div id="qiu">
  3. <h5 v-for="(u,index) in user">{{index}}:{{u.id}}
  4. <div v-for="(n,index_) in u.like">{{index_}}:{{n.cat}}</div>
  5. </h5>
  6. </div>
  7. <script src="../js2/vue.min.js"></script>
  8. <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
  9. <script>
  10. new Vue({
  11. el: '#qiu',
  12. data(){
  13. return {
  14. user:[]
  15. }
  16. },
  17. methods:{
  18. show1: function(){
  19. console.log("显示内容")
  20. },
  21. show2(){
  22. console.log("show2")
  23. },
  24. clickPaixu(IsAnswer,index){
  25. console.log("点击:" + IsAnswer)
  26. console.log("点击:" + index)
  27. this.num = IsAnswer;
  28. this.aa[index] = index;
  29. console.log("aa[index]:"+this.aa[index])
  30. }
  31. },
  32. created: function () {
  33. axios.get('test.json').then((response) => {
  34. console.log(response.data.user)
  35. this.user = response.data.user
  36. })
  37. },
  38. })
  39. </script>
  40. </body>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/76735
推荐阅读
相关标签
  

闽ICP备14008679号