vue中的$set方法更新了数据如何反映到视图层?
<div v-html='data.name' class="product-tit">
####
</div>
this.view = new vue({el: '#app',data:{'data':''}});
this.view.$set('data',{
'name' : 'zhusngq'
});
var _this = this;
setTimeout(function() {
_this.view.$set('data',{
'name' : 'zhusngqi'
});
}, 10000);
// 部分js对大家产生了疑惑下面贴出全部js。
/**
* Created by
*/
define(function (require) {
var $ = require('jquery');
var vue = require('vue');
var bxslider = require('bxslider');
// 构造函数
var PageModel = function (options) {
this.pageName = options.page;
this.module = options.module;
}
// 初始化页面js, 调用jquery的document.ready初始化页面DOM元素
PageModel.prototype.initialize = function() {
var pageModel = this;
$(document).ready(function(){
pageModel.onPageLoad();
});
}
// jquery 页面加载初始化
PageModel.prototype.onPageLoad = function () {
console.log("Page init");
this.control();
// 设置渲染
this.control();
}
PageModel.prototype.control = function () {
var _this = this;
$('.bxslider').bxSlider({auto : true, controls : false, touchEnabled : true });
// 创建一个vue对象;
this.view = new vue({el: '#app',data:{'data':''}});
this.view.$set('data',{
'name' : 'zhusngq'
});
setTimeout(function() {
_this.view.$set('data',{
'name' : 'zhusngqi'
});
}, 10000);
}
return PageModel;
});
先假设你只贴了部分代码,所以才没有解释this指向什么,#app的元素是哪一个
然后也假设你确实等了那10秒钟
其实这都不重要,重要的是new vue要大写new Vue
vue 不是双向绑定的么