- 如果跳轉到子組件(子組件時個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"
- 組件中在vuex中保存全局常用數據(數組對象),無法獲取到該數據
待處理
- 組件的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()
})
}
}
純屬個人疑惑,希望有更好的方法!