Vue avoid mutating a prop directly since the value will be overwritten
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>vue Learn</title>
- <script src="https://unpkg.com/vue/dist/vue.js"></script>
- </head>
- <body>
- <form id="form" method="post">
- <login></login>
- </form>
- <script src="./js/vue/v1.js"></script>
- </body>
- </html>
- (function(w) {
- Vue.component('login', {
- props: ['uName', 'uPwd'],
- template: '<section class="login">' +
- '<div class="form-group"><label>用户名</label><input id="txtUser" v-model="uName"/></div>' +
- '<div class="form-group"><label>密码</label><input id="txtPwd" type="password" v-model="uPwd"/></div>' +
- '<div class="form-group"><input type="submit" value="提交" v-bind:disabled="btndisable"/></div></section>',
- computed:{
- btndisable:function(){
- return (this.uName||'').length>0&&(this.uPwd||'').length>0?false:true;
- }
- }
- });
- new Vue({
- el: '#form'
- })
- })(window)
运行后,在用户名输入,console界面中弹出警告:
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: "uName" 。
修改之后:
- (function(w) {
- Vue.component('login', {
- props: ['uName', 'uPwd'],
- template: '<section class="login">' +
- '<div class="form-group"><label>用户名</label><input id="txtUser" v-model="name"/></div>' +
- '<div class="form-group"><label>密码</label><input id="txtPwd" type="password" v-model="pwd"/></div>' +
- '<div class="form-group"><input type="submit" value="提交" v-bind:disabled="btndisable"/></div></section>',
- data:function(){
- return {
- name:"",
- pwd:""
- }
- },
- computed:{
- btndisable:function(){
- return (this.name||'').length>0&&(this.pwd||'').length>0?false:true;
- }
- }
- });
- new Vue({
- el: '#form'
- })
- })(window)
运行OK,没有警告。
总结:
1.v-model 默认是双向绑定,开始时使用默认 属性uName 双向绑定,意味着存在,组件内部 修改uName,从而影响外部 组件的风险。
2.改正后,在组件内部再构建一套属性域,从而与外界解耦
Vue avoid mutating a prop directly since the value will be overwritten的更多相关文章
- [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 paren
今天在做Vue的时候,子组件关闭的时候,报如下错误 报错:vue.esm.js?65d7:610 [Vue warn]: Avoid mutating a prop directly since th ...
- 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报错之"[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 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 报错[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders
场景:父组件向子组件传递数据,子组件去试图改变父组件数据的时候. 解决:子组件通过事件向父组件传递信息,让父组件来完成数据的更改. 比如:我的父组件是普通页面,子组件是弹窗的登录界面,父组件传递的数据 ...
- Vue 错误:Avoid mutating a prop directly
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re- ...
- (复习)父子组件传值使用v-modal双向绑定,报错Avoid mutating a prop directly解决方案
报错:Avoid mutating a prop directly since the value will be overwritten whenever the parent component. ...
随机推荐
- win10编译maskrcnn benchmark
步骤 1. 按照官网的Option1安装步骤安装 https://github.com/facebookresearch/maskrcnn-benchmark/blob/master/INSTALL. ...
- yocto 编译C程序
1. 找到编译器位置所在(相关设置参考/opt/poky/1.7/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi文件) poky安装在 ...
- 迭代器遍历【List、Set、Map】
迭代器遍历[List.Set.Map] example package boom.collection; import java.util.ArrayList; import java.util.Ha ...
- BLE 5协议栈-逻辑链路控制与适配协议层(L2CAP)
文章转载自:http://www.sunyouqun.com/2017/04/page/2/ 逻辑链路控制与适配协议通常简称为L2CAP(Logical Link Control and Adapta ...
- C# 列表中查找大小比较
列表中查找大小比较
- 微信小程序开发(三)点击事件
接着上篇博客继续. 如下修改: // index.wxml <view>Hello World!</view> <button bindtap="but&quo ...
- RabbitMQ各种交换机类型Exchange Types介绍
最新版本的RabbitMQ有四种交换机类型,分别是Direct exchange.Fanout exchange.Topic exchange.Headers exchange. 一.Direct E ...
- IDEA部署Tomcat报错:No artifacts marked for deployment
刚开始碰到这个问题还被坑了,搞了好半天...所以我准备记录一下,走的弯路就不说了,因为我没图
- top命令参数详解
简介 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器. top显示系统当前的进程和其他状况,是一个动态显示过程,即可以通过用户按 ...
- java中int转成String位数不足前面补零
java中int转成String位数不足前面补零 转载自:http://ych0108.iteye.com/blog/2174134 java中int转String位数不够前面补零 String.fo ...