写了一个简单的demo是有用的,在新增的时候也可以用,但是编辑的时候却不能用,简单demo如下
<div id="app">
<input type="radio" v-model="showImage" value="0"/>
<input type="radio" v-model="showImage" value="1"/>
<div v-if="showImage==1">
{{message}}
</div>
</div>
<script>
var vm = new Vue({
el:'#app',
data:{
message:'hello',
showImage:0
}
})
</script>
我写的代码是这样的
var vm = new Vue({
el:'#dpLTE',
data: {
oldLoginName:'',
newLoginName:'',
oldRoleIds:[],
newRoleIds:[],
roleList:{},
multiple:'multiple',
user:{
disabled: false,
departmentName:'',
showImage:0
}
},
methods : {
departmentTree: function(){
dialogOpen({
id: 'layerDepartmentTree',
title: '选择',
url: 'sys/user/departmentTree?_=' + $.now(),
scroll : true,
width: "300px",
height: "450px",
yes : function(iframeId) {
top.frames[iframeId].vm.acceptClick();
}
});
},
uploadPic:function(){
var data = new FormData($('#uploadForm')[0]);
$.ajax({
url: '../../sys/upload/pic',
type: 'POST',
data: data,
async: false,
cache: false,
contentType: false,
processData: false,
success: function(r) {
var code = r.code;
var msg = r.msg;
if (code==0) {
var data = r.data;
var pic = data.picName;
vm.user.pic = pic;
dialogMsg(msg, 'success');
} else {
dialogMsg(msg, 'error');
}
},
error: function(data) {
console.log(data.status);
}
});
},
getRoleList: function(){
$.get('../../sys/role/select?_=' + $.now(), function(r){
var code = r.code;
var data = r.data;
if(code==0){
vm.roleList = data.rows;
}
});
},
setForm: function() {
$.SetForm({
url: '../../sys/user/infoUser?_=' + $.now(),
param: vm.user.id,
success: function(data) {
vm.user = data.user;
vm.oldRoleIds = vm.newRoleIds = data.roleIds;
vm.oldLoginName = vm.newLoginName = vm.user.loginname;
}
});
},
acceptClick: function() {
if (!$('#form').Validform()) {
return false;
}
var params = {"user":vm.user,"oldLoginName":vm.oldLoginName,"newLoginName":vm.newLoginName,"oldRoleIds":vm.oldRoleIds,"newRoleIds":vm.newRoleIds};
$.ConfirmForm({
url: '../../sys/user/editDo?_=' + $.now(),
param: params,
success: function(data) {
$.currentIframe().vm.load();
}
});
}
},
created : function() {
this.getRoleList();
}
})
前台就是和上面demo做的类似的,但是没有效果,setForm方法是填充表单用的,showImage不是user里面的属性,在data中设置没有效果,但是在setForm里面用vm.user.showImage=1的时候是有效果的,可是切换以后showImage并没有发生改变。这个是什么原因啊。一开始觉得数据绑定很好,后来发现有错了不知道哪里错了,叫兽 求救。。