• 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>
  • 相关阅读:
    Servlet
    MySQL游标
    MySQL数据库的备份和还原
    MySQL安全管理
    MySQL存储过程
    MySQL联结——实现多表查询
    MySQL视图
    MySQL触发器
    asp.net core 读取连接字符串
    form表单提交前进行ajax验证
  • 原文地址:https://www.cnblogs.com/rxfn/p/10656259.html
Copyright © 2020-2023  润新知