mirror of https://github.com/vuejs/core.git
fix(custom-elements): fix number type props casting check
fix #5793 adapted from #5794
This commit is contained in:
parent
afe889999c
commit
89f37ceb62
|
@ -228,6 +228,25 @@ describe('defineCustomElement', () => {
|
||||||
await nextTick()
|
await nextTick()
|
||||||
expect(el.shadowRoot!.innerHTML).toMatchInlineSnapshot('"<div>foo</div>"')
|
expect(el.shadowRoot!.innerHTML).toMatchInlineSnapshot('"<div>foo</div>"')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// # 5793
|
||||||
|
test('set number value in dom property', () => {
|
||||||
|
const E = defineCustomElement({
|
||||||
|
props: {
|
||||||
|
'max-age': Number
|
||||||
|
},
|
||||||
|
render() {
|
||||||
|
// @ts-ignore
|
||||||
|
return `max age: ${this.maxAge}/type: ${typeof this.maxAge}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
customElements.define('my-element-number-property', E)
|
||||||
|
const el = document.createElement('my-element-number-property') as any
|
||||||
|
container.appendChild(el)
|
||||||
|
el.maxAge = 50
|
||||||
|
expect(el.maxAge).toBe(50)
|
||||||
|
expect(el.shadowRoot.innerHTML).toBe('max age: 50/type: number')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('attrs', () => {
|
describe('attrs', () => {
|
||||||
|
|
|
@ -234,11 +234,15 @@ export class VueElement extends BaseClass {
|
||||||
// cast Number-type props set before resolve
|
// cast Number-type props set before resolve
|
||||||
let numberProps
|
let numberProps
|
||||||
if (props && !isArray(props)) {
|
if (props && !isArray(props)) {
|
||||||
for (const key in this._props) {
|
for (const key in props) {
|
||||||
const opt = props[key]
|
const opt = props[key]
|
||||||
if (opt === Number || (opt && opt.type === Number)) {
|
if (opt === Number || (opt && opt.type === Number)) {
|
||||||
this._props[key] = toNumber(this._props[key])
|
if (key in this._props) {
|
||||||
;(numberProps || (numberProps = Object.create(null)))[key] = true
|
this._props[key] = toNumber(this._props[key])
|
||||||
|
}
|
||||||
|
;(numberProps || (numberProps = Object.create(null)))[
|
||||||
|
camelize(key)
|
||||||
|
] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue