欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue父組件數(shù)據(jù)更新子組件相關(guān)內(nèi)容未改變問題(用watch解決)

 更新時(shí)間:2022年03月25日 14:50:59   作者:liuarmyliu  
這篇文章主要介紹了vue父組件數(shù)據(jù)更新子組件相關(guān)內(nèi)容未改變問題(用watch解決),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

父組件數(shù)據(jù)更新子組件相關(guān)內(nèi)容未改變

父組件

在父組件中,根據(jù)后臺給的數(shù)據(jù)(數(shù)組),v-for生成子組件

? ?<div class="exist">? ? ? ? ? ??
? ? ?? ?<existProject :itemprop="item" v-for="(item, index) in getData" :key="index" :index="index" @click="sendIdTogetData(index)" v-show="true"></existProject>
?? ?</div>

子組件(existProject)

<template>
?<!-- <transition name="el-zoom-in-center"> -->
? <div class="existProjectBox" v-show="show2">
? ? ? <div class="existContentBox">
? ? ? ? ? <div class="existContent">
? ? ? ? ? ? ? <div class="existTitle">{{itemprop.title}}</div>
? ? ? ? ? ? ? <div class="stateBox">
? ? ? ? ? ? ? ? ? <span class="state">{{ status_tit }}</span>
? ? ? ? ? ? ? ? ? <span class="number" v-if="itemprop.status==2">收集份數(shù):{{itemprop.asyncCount}}份</span>
? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? <div class="tiemBox">
? ? ? ? ? ? ? ? ? {{createtime}}
? ? ? ? ? ? ? </div>
? ? ? ? ? </div>
? ? ? </div>
? ? ? <div class="existButton">
? ? ? ? <li v-if="itemprop.status==0" @click="turnEdit(itemprop.qid)">
? ? ? ? ? ? <i class="icon icon-edit"></i>
? ? ? ? ? ? <span>編輯</span>
? ? ? ? </li>
? ? ? ? <li v-if="itemprop.status==0" @click="turnSend(itemprop.qid)">
? ? ? ? ? ? <i class="icon icon-send"></i>
? ? ? ? ? ? <span>發(fā)布</span>
? ? ? ? </li>
? ? ? ? <li v-if="itemprop.status==2 ">
? ? ? ? ? ? <i class="icon icon-data"></i>
? ? ? ? ? ? <span>數(shù)據(jù)</span>
? ? ? ? </li>
? ? ? ? <!-- <li v-if="itemprop.status==2 ">
? ? ? ? ? ? <i class="icon icon-data"></i>
? ? ? ? ? ? <span>暫停</span>
? ? ? ? </li>
? ? ? ? <li v-if="itemprop.status==2 ">
? ? ? ? ? ? <i class="icon icon-data"></i>
? ? ? ? ? ? <span>終止</span>
? ? ? ? </li> -->
? ? ? ? <li @click="delItem(itemprop.qid)">
? ? ? ? ? ? <i class="icon icon-other"></i>
? ? ? ? ? ? <span>刪除</span>
? ? ? ? </li>
? ? ? </div>
? </div>
?<!-- </transition> -->
</template>
<script>
import axios from 'axios'
export default {
? ? data(){w
? ? ? ? return{
? ? ? ? ? ? createtime:'',
? ? ? ? ? ? status_tit:'',
? ? ? ? ? ? show2:true
? ? ? ? }
? ? },
? ? props:['itemprop'],
? ? methods:{
? ? ? ? turnEdit(id){
? ? ? ? ? ? debugger;
? ? ? ? ? ? console.log(id)
? ? ? ? ? ? axios.defaults.headers.common['token'] = JSON.parse(window.localStorage.getItem('token'))
? ? ? ? ? ? axios.get('/question/'+id)
? ? ? ? ? ? .then(response => {
? ? ? ? ? ? ? ? console.log(response);
? ? ? ? ? ? ? ? var obj = response.data.data;
? ? ? ? ? ? ? ? var contents = obj.contents;
? ? ? ? ? ? ? ? for(let i = 0; i < contents.length; i++){
? ? ? ? ? ? ? ? ? ? obj.contents[i].component = this.$options.methods.initType(obj.contents[i].type)
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? console.log(obj)
? ? ? ? ? ? ? ? window.localStorage.setItem('workInfoList', JSON.stringify(obj));
? ? ? ? ? ? ? ? this.$router.push({
? ? ? ? ? ? ? ? ? ? path: '/edit',
? ? ? ? ? ? ? ? ? ? query: {
? ? ? ? ? ? ? ? ? ? ? ? id: id
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? window.location.reload()
? ? ? ? ? ? })
? ? ? ? ? ? .catch(error => {
? ? ? ? ? ? ? ? console.log(error)
? ? ? ? ? ? })
? ? ? ? },
? ? ? ? turnSend(id){
? ? ? ? ? ? debugger;
? ? ? ? ? ? console.log(id)
? ? ? ? ? ? axios.defaults.headers.common['token'] = JSON.parse(window.localStorage.getItem('token'))
? ? ? ? ? ? axios.get('/question/'+id)
? ? ? ? ? ? .then(response => {
? ? ? ? ? ? ? ? console.log(response);
? ? ? ? ? ? ? ? var obj = response.data.data;
? ? ? ? ? ? ? ? console.log(obj)
? ? ? ? ? ? ? ? window.localStorage.setItem('workInfoList', JSON.stringify(obj));
? ? ? ? ? ? ? ? this.$router.push({
? ? ? ? ? ? ? ? ? ? path: '/sendProject',
? ? ? ? ? ? ? ? ? ? query: {
? ? ? ? ? ? ? ? ? ? ? ? id: id
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? window.location.reload()
? ? ? ? ? ? })
? ? ? ? ? ? .catch(error => {
? ? ? ? ? ? ? ? console.log(error)
? ? ? ? ? ? })
? ? ? ? },
? ? ? ? delItem(id){
? ? ? ? ? this.$confirm('此操作將刪除該文件進(jìn)入草稿箱, 是否繼續(xù)?', '提示', {
? ? ? ? ? ? confirmButtonText: '確定',
? ? ? ? ? ? cancelButtonText: '取消',
? ? ? ? ? ? type: 'warning'
? ? ? ? ? })
? ? ? ? ? .then(() => {
? ? ? ? ? ??
? ? ? ? ? ? axios.defaults.headers.common['token'] = JSON.parse(window.localStorage.getItem('token'))
? ? ? ? ? ? axios.delete('/question/'+id)
? ? ? ? ? ? ? .then(response => {
? ? ? ? ? ? ? ? console.log(response)
? ? ? ? ? ? ? ? // this.show2 = false
? ? ? ? ? ? ? ? this.$parent.getPage();
? ? ? ? ? ? ? })
? ? ? ? ? })
? ? ? ? ? .catch(error => {
? ? ? ? ? ? ? console.log(error)
? ? ? ? ? })
? ? ? ? },
? ? ? ? initType(str){
? ? ? ? ? switch(str){
? ? ? ? ? ? ? case 1:return 'Radio';
? ? ? ? ? ? ? case 2:return 'check';
? ? ? ? ? ? ? case 3:return 'gapFill';
? ? ? ? ? ? ? case 4:return 'level';
? ? ? ? ? ? ? case 5:return 'photoInput';
? ? ? ? ? ? ? case 6:return 'Rate';
? ? ? ? ? ? ? case 7:return 'remark';
? ? ? ? ? ? ? case 8:return 'selectChoice';
? ? ? ? ? ? ? case 9:return 'sort';
? ? ? ? ? ? ? case 10:return 'tableNumber';
? ? ? ? ? ? ? case 11:return 'temp';
? ? ? ? ? }
? ? ? ? },? ? ? ??
? ? },
? ? mounted(){
? ? ? ? // console.log(this.itemprop.createTime)
? ? ? ? var transformTime = new Date(this.itemprop.createTime)
? ? ? ? this.createtime = transformTime.toLocaleString();
? ? ? ? console.log(this.createtime)
? ? },
}
</script>

因?yàn)橛卸鄺l數(shù)據(jù),所以有分頁處理,在第一頁中數(shù)據(jù)顯示正常,但是在獲得第二頁數(shù)據(jù)并賦值給父組件的data后,子組件的信息保留的還是第一頁的信息

解決方法,使用watch深度監(jiān)聽

? ? watch:{
? ? ? ? itemprop:{
? ? ? ? ? ? handler(n,o){?
? ? ? ? ? ? ? ? console.log(this.itemprop);
? ? ? ? ? ? ? ? var status = this.itemprop.status;
? ? ? ? ? ? ? ? var showCondition = this.itemprop.showCondition;
? ? ? ? ? ? ? ? // debugger;
? ? ? ? ? ? ? ? this.status_tit = (function(status,showCondition) {
? ? ? ? ? ? ? ? ? ? if(status==0) {
? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? return '未發(fā)布';
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? if(status==2 && showCondition==1)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? // 已發(fā)布
? ? ? ? ? ? ? ? ? ? ? ? return ?'收集中';
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? if(status==2 &&showCondition==0)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? // 暫停
? ? ? ? ? ? ? ? ? ? ? ? return '已暫停';
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? if(status==2 &&showCondition==-1) {
? ? ? ? ? ? ? ? ? ? ? ? // 終止
? ? ? ? ? ? ? ? ? ? ? ? return '已終止';
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? if(status==2 &&showCondition==2) {
? ? ? ? ? ? ? ? ? ? ? ? // 問卷發(fā)布結(jié)束
? ? ? ? ? ? ? ? ? ? ? ? return '已結(jié)束';
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? })(status,showCondition)
? ? ? ? ? ? },
? ? ? ? ? ? deep:true,
? ? ? ? ? ? immediate:true,
? ? ? ? }
? ? }

watch可以監(jiān)聽子組件的數(shù)據(jù)變化,數(shù)組或者對象要用深度監(jiān)聽,字符串什么的不用深度監(jiān)聽,這樣就可以在分頁切換數(shù)據(jù)后,就不會保留原有的信息,而是新的信息了

循環(huán)中子組件不更新問題

解決方法

這是Element-UI的一個(gè)bug,解決方案是從el-table中增加一個(gè)row-key屬性,并為row-key設(shè)置一個(gè)能唯一標(biāo)識的字段名。

1.這個(gè)可以是數(shù)據(jù)庫的id字段

<el-table row-key="_id" ></el-table>

2.給table增加一個(gè)隨機(jī)數(shù)的key

<el-table :key="Math.random()" ></el-table>

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue文件配置全局變量的實(shí)例

    Vue文件配置全局變量的實(shí)例

    今天小編就為大家分享一篇Vue文件配置全局變量的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • 利用Vue.js指令實(shí)現(xiàn)全選功能

    利用Vue.js指令實(shí)現(xiàn)全選功能

    最近做了兩個(gè)vue的項(xiàng)目,都需要實(shí)現(xiàn)全選反選的功能,兩個(gè)項(xiàng)目用了兩種實(shí)現(xiàn)方法,第一個(gè)項(xiàng)目用vue的computed,第二個(gè)項(xiàng)目用指令來實(shí)現(xiàn),用起來,發(fā)覺指令更加方便。下面就來介紹如何利用指令來實(shí)現(xiàn)全選。
    2016-09-09
  • vue組件傳值的實(shí)現(xiàn)方式小結(jié)【三種方式】

    vue組件傳值的實(shí)現(xiàn)方式小結(jié)【三種方式】

    這篇文章主要介紹了vue組件傳值的實(shí)現(xiàn)方式,結(jié)合實(shí)例形式總結(jié)分析了vue.js組建傳值的三種實(shí)現(xiàn)方式,包括父傳子、子傳父及非父子傳值,需要的朋友可以參考下
    2020-02-02
  • ElementUI修改實(shí)現(xiàn)更好用圖片上傳預(yù)覽組件

    ElementUI修改實(shí)現(xiàn)更好用圖片上傳預(yù)覽組件

    這篇文章主要為大家介紹了ElementUI修改實(shí)現(xiàn)更好用圖片上傳預(yù)覽組件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • Vue 2.0雙向綁定原理的實(shí)現(xiàn)方法

    Vue 2.0雙向綁定原理的實(shí)現(xiàn)方法

    這篇文章主要為大家詳細(xì)介紹了Vue 2.0雙向綁定原理的實(shí)現(xiàn)方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • 淺談vue 多個(gè)變量同時(shí)賦相同值互相影響

    淺談vue 多個(gè)變量同時(shí)賦相同值互相影響

    這篇文章主要介紹了淺談vue 多個(gè)變量同時(shí)賦相同值互相影響,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • vue-router 路由基礎(chǔ)的詳解

    vue-router 路由基礎(chǔ)的詳解

    這篇文章主要介紹了vue-router 路由基礎(chǔ)的詳解的相關(guān)資料,希望通過本文能幫助到大家,讓大家理解掌握這部分內(nèi)容,需要的朋友可以參考下
    2017-10-10
  • uniapp前端支付篇之微信、抖音、快手、h5四個(gè)平臺支付功能

    uniapp前端支付篇之微信、抖音、快手、h5四個(gè)平臺支付功能

    支付功能在我們?nèi)粘i_發(fā)中經(jīng)常會遇到,下面這篇文章主要給大家介紹了關(guān)于uniapp前端支付篇之微信、抖音、快手、h5四個(gè)平臺支付功能的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-03-03
  • vue監(jiān)聽滾動條頁面滾動動畫示例代碼

    vue監(jiān)聽滾動條頁面滾動動畫示例代碼

    Vue是一套用于構(gòu)建用戶界面的漸進(jìn)式框架,與其它大型框架不同的是,Vue?被設(shè)計(jì)為可以自底向上逐層應(yīng)用,下面這篇文章主要給大家介紹了關(guān)于vue監(jiān)聽滾動條頁面滾動動畫的相關(guān)資料,需要的朋友可以參考下
    2023-06-06
  • 利用Vue.js實(shí)現(xiàn)求職在線之職位查詢功能

    利用Vue.js實(shí)現(xiàn)求職在線之職位查詢功能

    Vue.js是當(dāng)下很火的一個(gè)JavaScript MVVM庫,它是以數(shù)據(jù)驅(qū)動和組件化的思想構(gòu)建的。下面這篇文章主要給大家介紹了關(guān)于利用Vue.js實(shí)現(xiàn)求職在線之職位查詢功能的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-07-07

最新評論