提交 3fd967a7 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat: defineModel 增加默认值示例及测试

上级 169ef6fc
......@@ -2,6 +2,7 @@
<view>
<text id="model-value-text">modelValue in Foo: {{modelValue}}</text>
<text class='uni-common-mt' id="msg-text">msg in Foo: {{msg}}</text>
<text class='uni-common-mt' id="default-num-text">num: {{defaultNum}}</text>
<button class='uni-common-mt' id="update-value-btn" @click='updateValue'>update value</button>
</view>
</template>
......@@ -11,7 +12,8 @@
const modelValue = defineModel({ type: String })
// 在被修改时,触发 "update:msg" 事件
const msg = defineModel('msg', { type: String })
const msg = defineModel('msg', { type: String, default: 'default msg' })
const defaultNum = defineModel('num', { type: Number, default: 10 })
const updateValue = () => {
modelValue.value += '1'
......
......@@ -20,8 +20,11 @@ describe('defineModel', () => {
const modelValueInput = await page.$('#model-value-input')
expect(await modelValueInput.property('value')).toBe('str')
const msgText = await page.$('#msg-text')
expect(await msgText.text()).toBe('msg in Foo: msg')
const msgText = await page.$('#msg-text')
expect(await msgText.text()).toBe('msg in Foo: msg')
const defaultNumText = await page.$('#default-num-text')
expect(await defaultNumText.text()).toBe('num: 10')
const msgInput = await page.$('#msg-input')
expect(await msgInput.property('value')).toBe('msg')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册