V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
plantain
V2EX  ›  Vue.js

使用 vue.js 时,如果 html 片段,被新的 Html 片段覆盖掉,怎么重新绑到 viewModel 上?直接使用 vue=new Vue(vueModel)来做,有没有副作用?

  •  
  •   plantain · 2015-07-19 21:39:05 +08:00 · 3011 次点击
    这是一个创建于 3202 天前的主题,其中的信息可能已经有所发展或是发生改变。
    1 条回复    2015-07-19 22:02:46 +08:00
    yyx990803
        1
    yyx990803  
       2015-07-19 22:02:46 +08:00   ❤️ 1
    这种情况需要注意的就是销毁旧的实例以避免内存泄露 `oldVm.$destroy()`
    如果还想顺带维持原 vm 的状态,可以在销毁前 `newVue.$data = oldVue.$data`.

    当然最好还是避免这种覆盖的情况...
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2296 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 16:12 · PVG 00:12 · LAX 09:12 · JFK 12:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.