zoukankan      html  css  js  c++  java
  • vue中列表切换,改变内容

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
    </head>
    <body>
      <div id="app">
        <button @click=goBack>返回</button>
        <ul v-for="list in mainList">
          <p>{{ list.name }}</p>
          <li v-for="items in list.child" @click="clickLi(items.child)">{{ items.title }}</li>
        </ul>
      </div>

      <script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
      <script>
        new Vue({
          el: '#app',
          data () {
            return {
              // 用来渲染的列表
              mainList: [
                {
                  name: '列表1',
                  child: [
                    { title: '项目一', child: 'list1' },
                    { title: '项目二', child: 'list2' },
                    { title: '项目三', child: 'list3' },
                    { title: '项目四' },
                    { title: '项目五' }
                  ]
                },
                {
                  name: '列表2',
                  child: [
                    { title: '项目一' },
                    { title: '项目二' },
                    { title: '项目三' },
                    { title: '项目四' },
                    { title: '项目五' }
                  ]
                },
                {
                  name: '列表3',
                  child: [
                    { title: '项目一' },
                    { title: '项目二' },
                    { title: '项目三' },
                    { title: '项目四' },
                    { title: '项目五' }
                  ]
                }
              ],

              // 上一步的列表
              prevList: null,

              allList: {
                list1: [
                  {
                    name: '列表1',
                    child: [
                      { title: '项目一', child: 'list1' },
                      { title: '项目二', child: 'list2' },
                      { title: '项目三', child: 'list3' },
                      { title: '项目四' },
                      { title: '项目五' }
                    ]
                  },
                  {
                    name: '列表2',
                    child: [
                      { title: '项目一' },
                      { title: '项目二' },
                      { title: '项目三' },
                      { title: '项目四' },
                      { title: '项目五' }
                    ]
                  },
                  {
                    name: '列表3',
                    child: [
                      { title: '项目一' },
                      { title: '项目二' },
                      { title: '项目三' },
                      { title: '项目四' },
                      { title: '项目五' }
                    ]
                  }
                ],
                list2: [
                  {
                    name: '列表a',
                    child: [
                      { title: '项目一', child: 'list1' },
                      { title: '项目二', child: 'list2' },
                      { title: '项目三', child: 'list3' },
                      { title: '项目四' },
                      { title: '项目五' }
                    ]
                  }
                ],
                list3: [
                  {
                    name: '列表I',
                    child: [
                      { title: '项目一', child: 'list1' },
                      { title: '项目二', child: 'list2' },
                      { title: '项目三', child: 'list3' },
                      { title: '项目四' },
                      { title: '项目五' }
                    ]
                  },
                  {
                    name: '列表II',
                    child: [
                      { title: '项目一' },
                      { title: '项目二' },
                      { title: '项目三' },
                      { title: '项目四' },
                      { title: '项目五' }
                    ]
                  }
                ],
              },
            }
          },

          methods: {
            clickLi (child) {
              console.log(child)
              if (child) {
                this.prevList = this.mainList;
                this.mainList = this.allList[child];
              } else {
                alert('暂时没有子项目');
              }
            },
            goBack () {
              if (this.prevList) {
                this.mainList = this.prevList;
                this.prevList = null;
              }
            }
          }
        });
      </script>
    </body>
    </html>
  • 相关阅读:
    android:sharedUserId
    SystemProperties cannot be resolved错误
    Mybatis(二)|搭建mybatis环境之注解版-简单搭配
    Eclipse构建Maven的SpringMVC项目
    IDEA新手使用教程(详解)(经典)
    IntelliJ IDEA 教程
    用注解的方式实现Mybatis插入数据时返回自增的主键Id
    eclipse使用git提交项目
    eclipse中使用自带git的常用操作
    myeclipse10.7安装git插件
  • 原文地址:https://www.cnblogs.com/rxfn/p/10656259.html
Copyright © 2011-2022 走看看