diff --git a/src/directive.js b/src/directive.js index cb9b70c2e..bd09689f1 100644 --- a/src/directive.js +++ b/src/directive.js @@ -16,6 +16,16 @@ export function update (el: any, binding: Object, vnode: any, oldVNode: any): vo t(el, binding, vnode) } +export function unbind (el: any, binding: Object, vnode: any, oldVNode: any): void { + if (!assert(el, vnode)) { return } + + el.textContent = '' + el._vt = undefined + delete el['_vt'] + el._locale = undefined + delete el['_locale'] +} + function assert (el: any, vnode: any): boolean { const vm: any = vnode.context if (!vm) { diff --git a/src/install.js b/src/install.js index 6ac4e473b..750206eeb 100644 --- a/src/install.js +++ b/src/install.js @@ -2,7 +2,7 @@ import { warn } from './util' import extend from './extend' import mixin from './mixin' import component from './component' -import { bind, update } from './directive' +import { bind, update, unbind } from './directive' export let Vue @@ -29,7 +29,7 @@ export function install (_Vue) { extend(Vue) Vue.mixin(mixin) - Vue.directive('t', { bind, update }) + Vue.directive('t', { bind, update, unbind }) Vue.component(component.name, component) // use object-based merge strategy diff --git a/test/unit/issues.test.js b/test/unit/issues.test.js index 0b0791ac6..782d391a1 100644 --- a/test/unit/issues.test.js +++ b/test/unit/issues.test.js @@ -1,5 +1,6 @@ import messages from './fixture/index' import { parse } from '../../src/format' +const compiler = require('vue-template-compiler') describe('issues', () => { let vm, i18n @@ -287,7 +288,7 @@ describe('issues', () => { }) describe('#259', () => { - it('this points to the right', (done) => { + it('this points to the right', done => { const vm = new Vue({ i18n: new VueI18n({ locale: 'en', @@ -314,4 +315,48 @@ describe('issues', () => { done() }) }) + + describe('#377', () => { + it('should be destroyed', done => { + const el = document.createElement('div') + const template = `
TIMEOUT : {{ timeout }}
+