zoukankan      html  css  js  c++  java
  • vue+elementUI项目获取数组最后一位,防止深拷贝问题

    1、父组件

    。。。  
    <div v-else-if="routerType == 'buttonAdd' || routerType == 'buttonEdit'"> <button-add :sortCodeBtn="sortCodeBtn" :menuItem="menuItem" :childrenItem="childrenItem" :content="content" @goBack="goBack"></button-add> </div> </template>

    2、申明

    <script>
    import data from './new_file.js'
    import add from './add_'
    import buttonAdd from './button_add'
    export default {
      components: {
        add,
        buttonAdd
      },
      data () {
        return {
          sortCodeBtn: 0,
    。。。。。
    

     3、获取目标值

    getButtonData (id) {
          let that = this
          that.table.loading = true
          this.$post('/resource/find_button_by_parentId', this.getDataform)
            .then(function (res) {
              that.table.loading = false
              if (res.code === 100) {
                let strList = JSON.stringify(res.data)
                const listPop = JSON.parse(strList).pop() //获取res.data数组的最后一位
                that.sortCodeBtn = listPop.sortCode + 1  // 得到res.data数组最后一位的排序sortCode并加1
                that.table.data = that.editDate(JSON.parse(strList))
    that.table.total = res.total } }) .catch(function (error) { that.table.loading = false })

    },

     4、子组件使用

    <script>
    export default {
      props: {
        sortCodeBtn: {  // 在 methods 方法中可以直接通过 this.sortCodeBtn 获取(父组件)传来的 sortCodeBtn 值
          type: Number
        },
        content: {
          type: String,
          default () {
            return '新增按钮列表'
          }
        }
      }
    },
    
     created () {
        this.$set(this.addFromData, 'sort', this.sortCodeBtn) // 可直接在钩子函数created中进行数据的传递
    }
    

      

  • 相关阅读:
    HDU 4619 Warm up 2 (多校)
    深入浅出Node.js (9)
    HDU 1106 排序(排序)
    字符串相关心得
    HDU 2547 无剑无我(数学)
    HDU 2549 壮志难酬(字符串,处理小数点)
    HDU 2551 竹青遍野(循环,水)
    HDU 2552 三足鼎立(数学函数)
    HDU 2555 陷阱(模拟,结构体数组)
    HDU 2561 第二小整数(排序,水)
  • 原文地址:https://www.cnblogs.com/sylys/p/13632892.html
Copyright © 2011-2022 走看看