diff --git a/src/compiler/directives/model.js b/src/compiler/directives/model.js
index a89332ee338..2c175e81615 100644
--- a/src/compiler/directives/model.js
+++ b/src/compiler/directives/model.js
@@ -39,7 +39,9 @@ export function genAssignmentCode (
): string {
const modelRs = parseModel(value)
if (modelRs.idx === null) {
- return `if (typeof (${assignment}) === 'object' && (${assignment}).type === 'input') { ${value}=(${assignment}).target.value } else { ${value}=${assignment} }`
+ return `if (typeof (${assignment}) === 'object' && (${assignment}).type === 'input') {` +
+ `${value}=(${assignment}).target.value || (${assignment}).target.attr.value` +
+ `} else { ${value}=${assignment} }`
} else {
return `$set(${modelRs.exp}, ${modelRs.idx}, ${assignment})`
}
diff --git a/test/weex/compiler/v-model.spec.js b/test/weex/compiler/v-model.spec.js
index c5f0401dc7b..995410dbdf5 100644
--- a/test/weex/compiler/v-model.spec.js
+++ b/test/weex/compiler/v-model.spec.js
@@ -6,7 +6,8 @@ describe('compile v-model', () => {
const { render, staticRenderFns, errors } = compile(`
`)
expect(render).not.toBeUndefined()
expect(render).toMatch(strToRegExp(`attrs:{"value":(x)}`))
- expect(render).toMatch(strToRegExp(`on:{"input":function($event){x=$event.target.attr.value}}`))
+ expect(render).toMatch(strToRegExp(`"input":function($event)`))
+ expect(render).toMatch(strToRegExp(`x=$event.target.attr.value`))
expect(staticRenderFns).toEqual([])
expect(errors).toEqual([])
})
@@ -14,7 +15,9 @@ describe('compile v-model', () => {
it('should compile other component with whole $event as the value', () => {
const { render, staticRenderFns, errors } = compile(`
`)
expect(render).not.toBeUndefined()
- expect(render).toMatch(strToRegExp(`model:{value:(x),callback:function ($$v) {x=$$v},expression:"x"}`))
+ expect(render).toMatch(strToRegExp(`callback:function`))
+ expect(render).toMatch(strToRegExp(`x=$$v`))
+ expect(render).toMatch(strToRegExp(`expression:"x"`))
expect(staticRenderFns).toEqual([])
expect(errors).toEqual([])
})
@@ -23,7 +26,8 @@ describe('compile v-model', () => {
const { render, staticRenderFns, errors } = compile(``)
expect(render).not.toBeUndefined()
expect(render).toMatch(strToRegExp(`attrs:{"value":(x)}`))
- expect(render).toMatch(strToRegExp(`on:{"input":function($event){x=$event.target.attr.value.trim()}}`))
+ expect(render).toMatch(strToRegExp(`"input":function($event)`))
+ expect(render).toMatch(strToRegExp(`x=$event.target.attr.value.trim()`))
expect(staticRenderFns).toEqual([])
expect(errors).toEqual([])
})
@@ -33,8 +37,9 @@ describe('compile v-model', () => {
expect(render).not.toBeUndefined()
expect(render).toMatch(strToRegExp(`attrs:{"value":(x)}`))
expect(render).toMatch(strToRegExp(`attrs:{"value":(y)}`))
- expect(render).toMatch(strToRegExp(`on:{"change":function($event){x=$event.target.attr.value.trim()}}`))
- expect(render).toMatch(strToRegExp(`on:{"change":function($event){y=$event.target.attr.value.trim()}}`))
+ expect(render).toMatch(strToRegExp(`"change":function($event)`))
+ expect(render).toMatch(strToRegExp(`x=$event.target.attr.value.trim()`))
+ expect(render).toMatch(strToRegExp(`y=$event.target.attr.value.trim()`))
expect(staticRenderFns).toEqual([])
expect(errors).toEqual([])
})
diff --git a/test/weex/runtime/events.spec.js b/test/weex/runtime/events.spec.js
index cad3994cc6e..2270ae8d556 100644
--- a/test/weex/runtime/events.spec.js
+++ b/test/weex/runtime/events.spec.js
@@ -141,4 +141,77 @@ describe('generate events', () => {
})
})
})
+
+ it('should work with v-model', (done) => {
+ const { render, staticRenderFns } = compileAndStringify(`
+
+ {{ msg }}
+
+
+ `)
+ const instance = createInstance(runtime, `
+ new Vue({
+ el: 'body',
+ data: {
+ msg: 'hello'
+ },
+ render: ${render},
+ staticRenderFns: ${staticRenderFns}
+ })
+ `)
+ setTimeout(() => {
+ const $text = instance.doc.body.children[0]
+ const $input = instance.doc.body.children[1]
+ expect($text.attr.value).toEqual('hello')
+ expect($input.attr.value).toEqual('hello')
+ $input.attr.value = 'world'
+ instance.$fireEvent($input.ref, 'input', {}, { attrs: $input.attr })
+ setTimeout(() => {
+ expect($input.attr.value).toEqual('world')
+ expect($text.attr.value).toEqual('world')
+ done()
+ }, 0)
+ }, 0)
+ })
+
+ it('should work with v-bind="$attrs" plus v-on="$listeners"', (done) => {
+ const childTemplate = compileAndStringify(`
+
+ `)
+ const { render, staticRenderFns } = compileAndStringify(`
+
+ {{ msg }}
+
+
+ `)
+ const instance = createInstance(runtime, `
+ new Vue({
+ el: 'body',
+ data: {
+ msg: 'hello'
+ },
+ render: ${render},
+ staticRenderFns: ${staticRenderFns},
+ components: {
+ child: {
+ render: ${childTemplate.render},
+ staticRenderFns: ${childTemplate.staticRenderFns}
+ }
+ }
+ })
+ `)
+ setTimeout(() => {
+ const $text = instance.doc.body.children[0]
+ const $input = instance.doc.body.children[1]
+ expect($text.attr.value).toEqual('hello')
+ expect($input.attr.value).toEqual('hello')
+ $input.attr.value = 'world'
+ instance.$fireEvent($input.ref, 'input', {}, { attrs: $input.attr })
+ setTimeout(() => {
+ expect($input.attr.value).toEqual('world')
+ expect($text.attr.value).toEqual('world')
+ done()
+ }, 0)
+ }, 0)
+ })
})