实际上我的问题标题表述的是由问题的,但是又找不到好的切题的表述 … 希望大神能进来吧<script language="JavaScript"> var app = { state: 0, page: {}, post: { getArticleList: function(){ console.log(app.page.pn); $.post('http://www.xxx.com.cn/api.php/Article/GetArtList',{ 'page': 1 },function(res){ console.log(app.page.pn); //console.log(app.page.$data.articleList); if(res.data.length > 0){ app.page.articleList = app.page.articleList.concat(res.data); app.page.pn = app.page.pn+1; } }); } } }; $(function(){ app.page = new Vue({ el: '#article-list', data: { pn: 3, articleList: [] }, methods: { doAjaxLoad: function(){ app.post.getArticleList(); } }, created: function(){ //console.log(this.pn); this.doAjaxLoad(); } }); //加载页面 //app.post.getArticleList(); });</script>代码如上,VUE生命周期 created 的时候,执行自定义方法 doAjaxLoaddoAjaxLoad 这个方法调用全局对象 app 里的 post 对象里的 getArticleList 方法问题来了为什么我在getArticleList方法一开始输出 vue 实例的 data 属性 pn 的值的时候是 undefined在ajax callback里就能取值甚至我在 doAjaxLoad 方法里输出 this.pn 也是有值的 !!为什么 ?原理 …
添加回答
举报
0/150
提交
取消
