2015-07-12 139 views
1

,所以我有一个快速的Vue公司JS的问题,这似乎很奇怪,我有以下VUE JS 2路数据绑定更新不及时

var home = new Vue({ 
el: '#home', 
data:{ 
    title: 'welcome to the app' 
} 
}); 

的正常工作,在我的HTML标题得到更新精...

现在,当我做到这一点

home.$data.title = 'this is the new title' 

的HTML

<div class="app-topbar">{{title | uppercase}}</div> 

不更新,我必须强制更新数据绑定或其他?

感谢萨姆

回答

0

你不需要home.$data.title,如果你对你的Vue的实例中,你可以简单地通过使用this.title更改标题值。

这是一个快速小提琴。

http://jsfiddle.net/stefkosmo/6x2v9y20/

+0

嗨抱歉没有更新此越早,如果要更新VUE实例外部变量是什么?所以在应用程序中有一些JavaScript的地方呢?谢谢 – user1997198

+0

您可以使用外部的home.title – Luc

0

当你想更新一个实例的数据,该记录方法是通过this.$set('title', 'this is the new title); 设置新的数据时,你这样做,实际上是什么框架呢,是重新执行你的模板和HTML更新

http://vuejs.org/api/instance-methods.html#vm- \ $设置(_keypath \,

0

在万不得已我也用Vue.forceUpdate()`

但确实在这里看起来像你应该简单地使用home.title


我的清单对于这类问题:

  • 计算的财产?
  • this.$set
  • 提防的箭头功能和lodash
  • 与成分:.sync