Vue 报错[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders
场景:父组件向子组件传递数据,子组件去试图改变父组件数据的时候。

解决:子组件通过事件向父组件传递信息,让父组件来完成数据的更改。
比如:我的父组件是普通页面,子组件是弹窗的登录界面,父组件传递的数据(reloginDialog)控制登录界面的显示(reloginDialog = true),当登陆成功后,子组件触发一个事件,父组件捕获后(reloginDialog = false)将登录界面隐藏。
父组件调用
<re-login :dialogProp="reloginDialog" @login-success="reloginDialog = $event"></re-login>
子组件详细【ReLogin.vue】
<template>
<v-layout row justify-center>
<v-dialog v-model="dialogProp" persistent max-width="500">
<v-card class="login-bg">
<v-card-text>
<v-container fluid fill-height>
<v-layout align-center justify-center row fill-height text-xs-center>
<v-flex xs12>
<v-card color="#ffffffe6">
<v-card-title></v-card-title>
<h1 class="headline text-xs-center">****管理系统</h1>
<v-form
ref="form"
lazy-validation
>
<v-flex class="xs8 offset-xs2">
<v-text-field
color="blue"
v-model="submitData.empCode"
label="用户名"
:rules="[rules.required]"
prepend-inner-icon="fas fa-user"
></v-text-field>
</v-flex>
<v-flex class="xs8 offset-xs2">
<v-text-field
color="blue"
v-model="submitData.password"
prepend-inner-icon="fas fa-lock"
:append-icon="show1 ? 'fas fa-eye' : 'fas fa-eye-slash'"
:rules="[rules.required, rules.min]"
:type="show1 ? 'text' : 'password'"
label="密码"
counter
@click:append="show1 = !show1"
></v-text-field>
</v-flex>
</v-form>
<v-flex class="xs8 offset-xs2">
<v-btn color="blue" block dark @click="login">登录</v-btn>
</v-flex>
<v-card-title></v-card-title>
</v-card>
<!--页面提示-->
<v-snackbar
v-model="snackbar.show"
multi-line
top
right
:timeout="snackbar.timeout"
color="blue-grey darken-4"
>
{{ snackbar.text }}
<v-btn
color="pink"
flat
fab
dark
@click="snackbar.show = false"
>
<v-icon>fas fa-times</v-icon>
</v-btn>
</v-snackbar>
</v-flex>
</v-layout>
</v-container>
</v-card-text>
</v-card>
</v-dialog>
</v-layout>
</template> <script>
export default {
name: "ReLogin",
props: ['dialogProp'],
data: () => ({
// 全局提示
snackbar: {
show: false,
timeout: 6000,
text: ''
},
show1: false,
submitData:{
empCode: '',
password:''
},
rules: {
required: value => !!value || '请填写此字段.',
min: v => v.length >= 6 || '最少6个字符'
}
}),
methods: {
login: function () {
let me = this;
let tip = this.snackbar;
let store = this.$store;
if (!this.$refs.form.validate()) {
tip.show = true;
tip.text = '请检查字段是否符合规则';
return;
}
store.state.axios.post('/admin/login', this.submitData)
.then(function (response) {
let data = response.data;
if (data.code == 0){
sessionStorage.setItem('LOGIN_TOKEN',JSON.stringify(data.data));
me.$emit('login-success',false);
me.submitData = {
empCode: '',
password:''
};
} else{
tip.show = true;
tip.text = data.msg;
}
})
.catch(function (error) {
console.log(error);
tip.show = true;
tip.text = error;
}); }
}
}
</script> <style scoped>
.login-bg{
/*background-image: url("../assets/bg.jpg");*/
background-image: url("../assets/bg-2.jpeg");
background-position: center;
background-size: cover;
}
</style>
关键在于这句话,触发父组件的事件
me.$emit('login-success',false);
当用户身份过期需要登录的时候

登陆成功之后隐藏登录面板,继续之前没完成的操作
Vue 报错[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders的更多相关文章
- 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 ...
- 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 ...
- [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 ...
- 报错:[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
项目中遇到父组件传值 activeIndex <Tabs :tabs="tabs" :activeIndex="activeIndex" >< ...
- Avoid mutating a prop directly since the value will be overwritten whenever the parent component re
子组件修改父组件的值踩坑 Vue1.0升级至2.0之后,直接在子组件修改父组件的值是会报错的 目的是为了阻止子组件影响父组件的数据. 我们都知道在vue中,父组件传入子组件的变量是存放在props属性 ...
- 报错:[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 ...
- Vue avoid mutating a prop directly since the value will be overwritten
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- (复习)父子组件传值使用v-modal双向绑定,报错Avoid mutating a prop directly解决方案
报错:Avoid mutating a prop directly since the value will be overwritten whenever the parent component. ...
- Vue 错误:Avoid mutating a prop directly
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re- ...
随机推荐
- Docker-compose command 有多个命令例子
cat docker-compose.yml version: '3.4' services: klvchen: image: python_django:19.03.0 ports: - 8000: ...
- Umi+Dva搭建Cesium 3D开发环境
umi,中文可发音为乌米,是一个可插拔的企业级 react 应用框架,是蚂蚁金服的底层前端框架,已直接或间接地服务了 600+ 应用,包括 java.node.H5 无线.离线(Hybrid)应用.纯 ...
- 【Android】用Cubism 2制作自己的Live2D——初探Live2D在Android上的运行!
前言- 上一次我们成功运行了官方给我们的样本,是不是很有干劲啊?!这次我们就来看看Live2D是怎么在手机上运行的! 准备- 上次运行成功的官方样本——第一次我们先看简单的,就是那个名字叫Sample ...
- ElasticSearch-6.3.2 linux 安装
在linux 系统安装ElasticSearch-6.3.2最新版本,也适合6.x 系列版本做参考 前提先在linux 安装好jdk1.8 创建用户 从5.0开始,ElasticSearch 安全级别 ...
- iOS:我的学习路径
1.复习C语言(半个月) <C Primer Plus>1-6章 2.学习Objective-C基础语法(一周) 黑马程序员视频 3.直接用Xcode开始APP的实战(半个月) 黑马程序员 ...
- java或Jmeter实现两个日期相加减(2003-06-01-2003-05-01)
在beanshell中写入如下代码, import java.io.FileInputStream; SimpleDateFormat myFormatter = new SimpleDateForm ...
- XE5 搭建DataSnap服务
1 准备工作 1.1 环境准备 XE5或XE7,操作系统Windows7(64位)操作系统. 数据库MSSQL选择SQLServer2008. 如果数据库服务没有在开发电脑上,则需要在开发电脑上安 ...
- 吴军武志红万维刚薛兆丰何帆曾鸣李笑来罗永浩等得到APP专栏作者的书3
整理了一下最近两三年内看过的得到APP专栏与课程作者的得到精选文集和他们写过的书共本.新增吴军1本,武志红1本. 其中:武志红3本,熊太行1本,薛兆丰2本,吴军4本,何帆3本,曾鸣2本,万维刚1本,李 ...
- ThreadLocal<T>学习总结
public class ThreadLocalTest { /** * @param * @Author: xdj * @Date: 2019/4/12 10:16 * @Description: ...
- jackson把json转换成LIst
把json数据转换成list ObjectMapper mapper = new ObjectMapper(); List<YeWuLuYou> readValue = mapper.r ...