plantain
V2EX  ›  Vue.js

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

  •  
  •   plantain · Jul 19, 2015 · 4167 views
    This topic created in 3971 days ago, the information mentioned may be changed or developed.
    1 replies    2015-07-19 22:02:46 +08:00
    yyx990803
        1
    yyx990803  
       Jul 19, 2015   ❤️ 1
    这种情况需要注意的就是销毁旧的实例以避免内存泄露 `oldVm.$destroy()`
    如果还想顺带维持原 vm 的状态,可以在销毁前 `newVue.$data = oldVue.$data`.

    当然最好还是避免这种覆盖的情况...
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6007 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 02:57 · PVG 10:57 · LAX 19:57 · JFK 22:57
    ♥ Do have faith in what you're doing.