【Element】The data property "loading" is already declared as a prop. Use prop default value instead.

 报错信息

The data property "loading" is already declared as a prop. Use prop default value instead.

default{data}中的“loading”属性已经在 default{props} 中定义。默认使用  default{props}中的属性值替代。

vue.runtime.esm.js:619 [Vue warn]: The data property "loading" is already declared as a prop. Use prop default value instead.

found in

---> <TabPane>
       <ElTabPane> at packages/tabs/src/tab-pane.vue
         <ElTabs> at packages/tabs/src/tabs.vue
           <Tab> at src/views/tab/hejiinfo/hejidata/index.vue
             <Index> at src/views/tab/hejiinfo/index.vue
               <AppMain> at src/layout/components/AppMain.vue
                 <Layout> at src/layout/index.vue
                   <App> at src/App.vue
                     <Root>

 

Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "loading"

因为父组件每次重新渲染时,该值都会被修改,为了避免直接更改“props”中的属性值,根据 Props 属性值而是使用 data 或者 computed 基于属性来替代。 Prop 的“loading”属性被篡改

vue.runtime.esm.js:619 [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "loading"

found in

---> <TabPane>
       <ElTabPane> at packages/tabs/src/tab-pane.vue
         <ElTabs> at packages/tabs/src/tabs.vue
           <Tab> at src/views/tab/hejiinfo/hejidata/index.vue
             <Index> at src/views/tab/hejiinfo/index.vue
               <AppMain> at src/layout/components/AppMain.vue
                 <Layout> at src/layout/index.vue
                   <App> at src/App.vue
                     <Root>

 

源码

<template>
  <section>
    <el-table v-loading="loading" :data="list" border fit highlight-current-row style="width: 100%">
    <!--...-->
    </el-table>
    <el-pagination>
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
       <!--...-->
    </el-pagination>
  </section>
</template>

<script>
  //...
  export default {
    props: {
      //...
      loading:{
        type: Boolean,
        default: false
      },

    },
    data() {
      return {
        list: null,
        //...
        loading: false,
        //...
      }
    },
    methods: {
      getList() {
         //...
          this.loading=true
         //...
      },
      //...
      handleSizeChange(val) {
        //...
        this.getList()
      },
      handleCurrentChange(val) {
        //...
        this.getList()
      },    
      //...
    }
  }
</script>

解决方案

1、The data property "loading" is already declared as a prop. Use prop default value instead.

default{data} 与 data{props}中的loading属性只保留一个。

<script>
  //...
  export default {
    props: {
      //...
      loading:{
        type: Boolean,
        default: false
      },

    },
    data() {
      return {
        list: null,
        //...
        //loading: false,
        //...
      }
    },
  }
</script>

2、Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "loading"

如果父组件重新渲染会修改该值,则该值最好存放在data属性中 default{data} 。

<script>
  //...
  export default {
    props: {
      //...
      //loading:{
      //  type: Boolean,
      //  default: false
      //},

    },
    data() {
      return {
        list: null,
        //...
        loading: false,
        //...
      }
    },
  }
</script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值