报错:[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 bei

时间:2022-09-08 18:17:11

项目中遇到父组件传值 activeIndex

 <Tabs :tabs="tabs" :activeIndex="activeIndex" ></Tabs>
<script >
export default{
updated(){
let currentRoute=this.$route.name;
var arr=Array.from(this.$store.state.app.tabs);
if(arr.indexOf(currentRoute)!=-1){ this.activeIndex=this.$store.state.app.activeIndex=arr.indexOf(currentRoute).toString();
} }
}
</script>

子组件接收该值

 1 <template>
<el-tabs type="card" v-model="activeIndex" >
<el-tab-pane v-for="(item,index) in tabs" :label="item" :closable="index==0?false:true" :name="index.toString()" ></el-tab-pane>
</el-tabs>
</template> <script>
export default{
data(){
return {
tabs:[],
}
}, props:['activeIndex'] }
</script>

报错:[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 bei

参考网址https://juejin.im/entry/5843abb1a22b9d007a97854c
由于父组件updated()方法中更改了this.activeIndex值,update方法除了父组件触发这个方法,子组件也会触发,即子组件会更改activeIndex的值,但是由于父子组件的传递机制,会造成报错Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders....
因此在子组件使用该值时需要经过新变量(currentIndex)重新传递,这样当这个值变更时,不会造activeIndex的更改
 
 //v-model绑定更改
<el-tabs type="card" v-model="currentIndex" >
</el-tabs>
<script>
export default{
data(){
return {
tabs:[],
currentIndex:this.activeIndex //currentIndex接收父组件传来的activeIndex值;
}
}, props:['activeIndex'] }
</script> 作者:saintkl
链接:https://www.jianshu.com/p/392145843afe
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

报错:[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 bei的更多相关文章

  1. vue报错 &lbrack;Vue warn&rsqb;&colon; Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders&period; Instead&comma; use a data or computed property based on the prop&&num;39&semi;s

    [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent c ...

  2. Vue 报错&lbrack;Vue warn&rsqb;&colon; Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders

    场景:父组件向子组件传递数据,子组件去试图改变父组件数据的时候. 解决:子组件通过事件向父组件传递信息,让父组件来完成数据的更改. 比如:我的父组件是普通页面,子组件是弹窗的登录界面,父组件传递的数据 ...

  3. &lbrack;Vue warn&rsqb;&colon; Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders&period; Instead&comma; use a data or computed property based on the prop&&num;39&semi;s value&period; Prop being

    [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent c ...

  4. Avoid mutating a prop directly since the value will be overwritten whenever the parent component re

    子组件修改父组件的值踩坑 Vue1.0升级至2.0之后,直接在子组件修改父组件的值是会报错的 目的是为了阻止子组件影响父组件的数据. 我们都知道在vue中,父组件传入子组件的变量是存放在props属性 ...

  5. 报错:&lbrack;Vue warn&rsqb;&colon; Avoid mutating a prop directly since the value will be overwritten whenever the paren

    今天在做Vue的时候,子组件关闭的时候,报如下错误 报错:vue.esm.js?65d7:610 [Vue warn]: Avoid mutating a prop directly since th ...

  6. vue报错&lbrack;Vue warn&rsqb;&colon; The data property &quot&semi;record&quot&semi; is already declared as a prop&period; Use prop default value instead&period;

    当我写了一个子组件,点击打开子组件那个方法时报了一个错 这句话说明意思呢?谷歌翻译一下↓ 数据属性“record”已声明为prop. 请改用prop默认值. 感觉翻译的有点怪,通过最后修改代码后大概意 ...

  7. vue报错&lbrack;Vue warn&rsqb;&colon; Unknown custom element&colon; &lt&semi;router-Link&gt&semi; - did you register the component correctly&quest; For recursive components&comma; make sure to provide the &quot&semi;name&quot&semi; option&period;

    vue浏览器报错,如下 vue.runtime.esm.js?2b0e:619 [Vue warn]: Unknown custom element: <router-Link> - di ...

  8. Vue报错 &lbrack;Vue warn&rsqb;&colon; Cannot find element

    在前端开发全面进入前端的时代 作为一个合格的前端开发工作者 框架是不可或缺的Vue React Anguar 作为前端小白,追随大佬的脚步来到来到博客园,更新现在正在学习的Vue 注 : 相信学习Vu ...

  9. iview报错&lbrack;Vue warn&rsqb;&colon; Error in render&colon; &quot&semi;TypeError&colon; ctx&period;injections&period;tableRoot&period;&dollar;scopedSlots&lbrack;ctx&period;props&period;column&period;slot&rsqb; is not a function&quot&semi;

    原因是我使用了iview的<Table>组件,我给Table组件的columns中定义了4个含有slot的列,但是实际在<Table>中只使用了其中3个,导致的报错. 也就是说 ...

随机推荐

  1. Intellij IDE 常用设置

    1· 去除代码提示的Case sensitive(比如Sprite,键入sprite不进行任何提示) Editor->Code Completion->Case sensitive com ...

  2. iOS 应用中有页面加载gif动画,从后台进入前台时就消失了

    解决办法: 在Appdelegate.m 里面有一个从后台进入前台所响应的方法,可以在该方法里post 一个通知,在加载动画里的页面接受通知,响应一定的方法即可 #pragma -mark 当程序进入 ...

  3. 使用X-UA-Compatible来设置IE8&sol;IE9兼容模式

    文件兼容性用于定义让IE如何编译你的网页.此文件解释文件兼容性,如何指定你网站的文件兼容性模式以及如何判断一个网页该使用的文件模式. 前言 为了帮助确保你的网页在所有未来的IE版本都有一致的外观,IE ...

  4. MYSQL BLOB 字段大小以及个数的限制測试。

    測试结论 mysql版本号 5.1     表类型: innodb, row_format=compact (这是默认的行格式)     插入超过10个blob, blob的数据量非常小(<76 ...

  5. &lpar;转&rpar;linux中常用的头文件

    头文件主目录include 头文件目录中总共有32个.h头文件.其中主目录下有13个,asm子目录中有4个,linux子目录中有10个,sys子目录中有5个.这些头文件各自的功能如下,具体的作用和所包 ...

  6. Laravel的ORM入门

    源码目录在\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Relations下 关系:一对多(One To Many) 场景:每篇 ...

  7. OpenSSL中的大数接口与基于其的自用RSA加密接口设计

    本文记录了初次接触OpenSSL中的大数模块,重温了RSA加密流程,使用OpenSSL的接口包装成自用RSA加密接口,并且利用自己的接口演示了Alice与Bob通过RSA加密进行通讯的一个示例. 概览 ...

  8. 当前时间、前n天、后n天、取前n条记录、从第n条开始取m条

    当前时间:NOW() 前n天:DATE_SUB(NOW(),INTERVAL n DAY) 后n天:DATE_SUB(NOW(),INTERVAL -n DAY) 取前n条记录:SELECT * FR ...

  9. Oracl 一条sql语句 批量添加、修改数据

    最近一直在用,也一直在学oralc,项目上也用到了批量的添加(读取上传CSV文件信息,把符合条件的信息写入到数据库中),在写的时候想到了可能是数据量大就想该怎么快,(由于本人在.NET开发期间没有做过 ...

  10. rem设置

    html{ font-size:10vw; }