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>
  • 相关阅读:
    python selenium
    selenium 遇到chrome 弹出是否保存密码框
    selenium实现在新窗口打开链接
    linux 查看日志
    Selenium+Python :WebDriver设计模式( Page Object )
    Python Logging模块的简单使用
    【工作感悟】——员工因公司而加入,却因中层管理而离开
    【工作感悟】——如何协调人与事?
    J2EE的十三个技术——EJB之消息驱动JMS
    J2EE的十三个技术——EJB之实体Bean
  • 原文地址:https://www.cnblogs.com/rxfn/p/10656259.html
Copyright © 2011-2022 走看看