项目中遇到父组件传值 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>

参考网址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报错 [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

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

  2. Vue 报错[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders

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

  3. Vue报错之"[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead......"

    一.报错截图 [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the p ...

  4. [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

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

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

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

  6. 报错:[Vue warn]: 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 ...

  7. vue报错[Vue warn]: The data property "record" is already declared as a prop. Use prop default value instead.

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

  8. vue报错[Vue warn]: Unknown custom element: <router-Link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

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

  9. Vue报错 [Vue warn]: Cannot find element

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

随机推荐

  1. 当你「ping 一下」的时候,你知道它背后的逻辑吗?

    我们在遇到网络不通的情况,大家都知道去 ping 一下,看一下网络状况.那你知道「ping」命令后背的逻辑是什么吗?知道它是如何实现的吗? 一.「ping」命令的作用和原理? 简单来说,「ping」是 ...

  2. leetcode — reverse-linked-list

    /** * Source : https://leetcode.com/problems/reverse-linked-list/ * * * Reverse a singly linked list ...

  3. 用StyleCop规范团队代码

    前言 编码风格,每个人都是有不同的特点,风格各异,而且一个人在不同的时期,编码风格的差异也可能是非常大的,好比学生时代,刚工作的时候,工作一段时间后等. 在一个团队中,或一个项目中,如果出现了N种风格 ...

  4. JDK源码分析(三)—— LinkedList

    参考文档 JDK源码分析(4)之 LinkedList 相关

  5. 服务器配置用户信息、ssh免密码登录和防火墙等安全配置

    一.登录服务器      1.回到根目录 cd ~      2.ssh + 用户名@服务器公网地址 ssh root@47.94.208.76      3.输入密码:注意输入法大小写 二.查看服务 ...

  6. [转]gitlab配置通过smtp发送邮件(QQ exmail腾讯企业为例)

    本文转自:http://www.fayfox.com/post/39.html 首先祭出官网文档链接:https://docs.gitlab.com/omnibus/settings/smtp.htm ...

  7. Nginx 初識

    今天簡單了解了一下Nginx,并在本機安裝,并簡單配置了一下,道理什麼的還不懂,就是看能不能跑起來. 1.安裝從官網下載就好,把文件隨便解壓在一個英文目錄裡面. 然後修改配置文件,修改的內容如下: 2 ...

  8. Java基础:Object类中的equals与hashCode方法

    前言 这个系列的文章主要用来记录我在学习和复习Java基础知识的过程中遇到的一些有趣好玩的知识点,希望大家也喜欢. 一切皆对象   对于软件工程来说面向对象编程有一套完整的解决方案:OOA.OOD.O ...

  9. v8 GC机制

    1.为什么要分代 V8是Chrome浏览器的javascript解释器,为什么需要把堆分代?不分代不能完成他所做的事情么?其实不分代完全可以,分代的唯一理由就是优化GC性能.你先想想,如果没有分代,那 ...

  10. ASP.NET Core 一步步搭建个人网站(1)_环境搭建

    ASP.NET Core2.0发布有一阵子了,这是.NET 开源跨平台的一个重大里程碑, 也意味着比1.0版本要更加成熟.目前.net core具有开源.跨平台.灵活部署.模块化架构等等特性,吸引着一 ...