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中進行數據的傳遞
}

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM