https://uniapp.dcloud.net.cn/component/form.html#form
使用内置 behaviors 小结中介绍了如何使用“uni://form-field”,但是我发现,给出的代码无法正确运行(即表单提交后,结果为{})。经测试,我发现该代码能在Vue2的环境下正确运行,请问,要升级到Vue3我该如何修改?
基于Vue3的环境,我试着对该段代码进行了修改,但是仍旧无法正确运行,代码如下:
<!-- /pages/index/index.vue -->
<template>
<view class="content">
<form @submit="onSubmit">
<uni-comp-input name="test" v-model:value="testValue"></uni-comp-input>
<button form-type="submit">Submit</button>
</form>
</view>
</template>
<script>
export default {
data() {
return {
testValue: 'Hello'
}
},
methods: {
onSubmit(e) {
console.log(e.detail.value)
}
}
}
</script>
<style>
</style>
<!-- /components/uni-comp-input/uni-comp-input.vue -->
<template>
<view>
<input style="border: solid 1px #999999;height: 80px;" type="text" @input="onInput" :name="name"
:value="value" />
</view>
</template>
<script>
export default {
behaviors: ['uni://form-field'],
methods: {
onInput(e) {
this.$emit('update:value', e.detail.value)
}
}
}
</script>
<style>
</style>
望不吝赐教,谢谢!
2 个回复
j***@163.com
同问,vue3无效.
DCloud_UNI_Anne
HBuilderX3.6.7-alpha已修复