VUE+VUEX+Element项目中遇到的问题

  1. 如果跳转到子组件(子组件时个dialog弹窗)
    解决办法之一:
    this.$refs.Details.showDetail(参数) : Details的值是子组件中ref的值,showDetail是子组件中对应得方法
    代码如下:
    父组件:
    VUE
<el-button @click="showHandle(scope.row.id)" type="text" size="small"><i class="el-icon-view"></i>
                </el-button>
                <v-detail ref="Details"></v-detail>

JS

  import Details from './Details'
   showHandle (id) {
        this.$refs.Details.showDetail(id)
      },

子组件

<el-dialog title="商品详情"
               ref="Details"
               :modal="true"
               v-if="isShow"
               v-loading="loading"
               :visible.sync="isShow" :show-close="true"
               :center="true" width="600px"
               :before-close="modalClose"
               :close-on-click-modal="false"
               :close-on-press-escape="true"
               :append-to-body="true">
      <p>提示:{{shop}}</p>
    </el-dialog>

JS

 showDetail (id) {
        this.isShow = true
        this.$store.dispatch('shop/findShop', id).then((res) => {
          let data = this.$store.getters.shop
          this.shop = data
        })
      }

目前还存在一个问题: 翻页过后会出现以下,Error in v-on handler: "TypeError: Cannot read property 'showDetail' of undefined"

  1. 组件中在vuex中保存全局常用数据(数组对象),无法获取到该数据

待处理

  1. 组件的Form 表单 resetField只能针对字符串,对于数组/对象/数组对象如何处理
    基础类型
    对数据进行深度拷贝:
    代码如下:

子组件

onSubmit () {
        this.$emit('updatePrices', this.prices)
        this.$refs['prices'].resetFields()
      }

父组件

 // 子组件更新值
      pricesUpdate (shopPrice) {
      // 深度拷贝
        let data = JSON.parse(JSON.stringify(shopPrice))
        this.form.shopPrices = [...this.form.shopPrices, data]
      },

对象:
目前我的处理方法是:在进行触发事件得时候,对对象进行判断,如果事件是我给定得指定事件,将对象或者对象数组进行初始化
具体代码如下

页面代码中有个click事件

 <el-form-item label="区排号" prop="seats" v-if=" prices.shopSeats.length===0">
          <el-button type="primary" icon="el-icon-circle-plus" circle @click="addSeat('add')"></el-button>
        </el-form-item>

JS

addSeat (event) {
        if (event === 'add') {
          this.prices.shopSeats = [{}]
        } else {
          this.prices.shopSeats.push({
            value: '',
            key: Date.now()
          })
        }
      }

纯属个人疑惑,希望有更好的方法!

你可能感兴趣的:(前端(VUE,JS))