提交 9250316a 编写于 作者: 雪洛's avatar 雪洛

Update form.md

上级 585d893c
......@@ -94,6 +94,72 @@
```
![uniapp](https://img-cdn-qiniu.dcloud.net.cn/uniapp/doc/img/form.png?t=201857)
**微信小程序注意事项**
微信小程序端在`from`内的自定义组件内有`input`等表单控件时,无法在`form``submit`事件内获取组件内表单控件值,此时可以使用微信提供的[behaviors](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/behaviors.html)来做一下兼容。参考以下示例:
```html
<!-- /pages/index/index.vue -->
<template>
<view class="content">
<form @submit="onSubmit">
<comp-input name="test" v-model="testValue"></comp-input>
<button form-type="submit">Submit</button>
</form>
</view>
</template>
<script>
export default {
data() {
return {
testValue: 'Hello'
}
},
methods: {
onSubmit(e) {
console.log(e)
}
}
}
</script>
<style>
</style>
```
```html
<!-- /components/compInput/compInput.vue -->
<template>
<view>
<input name="test" style="border: solid 1px #999999;height: 80px;" type="text" @input="onInput" :value="value" />
</view>
</template>
<script>
export default {
name: 'compInput',
behaviors: ['wx://form-field'],
props: {
value: {
type: String,
default: ''
}
},
methods: {
onInput(e) {
this.$emit('input', e.detail.value)
}
}
}
</script>
<style>
</style>
```
**tips**
- [插件市场](http://ext.dcloud.net.cn/search?q=%E8%A1%A8%E5%8D%95%E6%A0%A1%E9%AA%8C)有表单校验插件
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册