提交 467ca202 编写于 作者: H hdx

unicloud-db-contact: add页面 使用form组件获取表单提交数据

上级 72141cf4
...@@ -3,32 +3,34 @@ ...@@ -3,32 +3,34 @@
<unicloud-db ref="udb" v-slot:default="{error}" :collection="collection" loadtime="manual"> <unicloud-db ref="udb" v-slot:default="{error}" :collection="collection" loadtime="manual">
<view v-if="error!=null" class="error">{{error.errMsg}}</view> <view v-if="error!=null" class="error">{{error.errMsg}}</view>
</unicloud-db> </unicloud-db>
<view class="form-item"> <form @submit="onFormSubmit">
<text class="form-item-label">姓名</text> <view class="form-item">
<input class="form-item-input" placeholder="姓名" v-model="username" /> <text class="form-item-label">姓名</text>
</view> <input class="form-item-input" placeholder="姓名" name="username" />
<view class="form-item"> </view>
<text class="form-item-label">电话</text> <view class="form-item">
<input class="form-item-input" placeholder="电话" v-model="mobile" /> <text class="form-item-label">电话</text>
</view> <input class="form-item-input" placeholder="电话" name="mobile" />
<view class="form-item"> </view>
<text class="form-item-label">邮箱</text> <view class="form-item">
<input class="form-item-input" placeholder="邮箱地址" v-model="email" /> <text class="form-item-label">邮箱</text>
</view> <input class="form-item-input" placeholder="邮箱地址" name="email" />
<view class="form-item"> </view>
<text class="form-item-label">备注</text> <view class="form-item">
<textarea class="form-item-input" placeholder="备注" v-model="comment" /> <text class="form-item-label">备注</text>
</view> <textarea class="form-item-input" placeholder="备注" name="comment" />
<view class="form-item"> </view>
<text class="form-item-label">性别</text> <view class="form-item">
<radio-group class="radio-list" @change="radioChange"> <text class="form-item-label">性别</text>
<view class="radio-item" v-for="(item, _) in genderList" :key="item.value"> <radio-group class="radio-list" name="gender">
<radio :value="item.value" :checked="item.value == gender" /> <view class="radio-item" v-for="(item, _) in genderList" :key="item.value">
<text>{{item.text}}</text> <radio :value="item.value" />
</view> <text>{{item.text}}</text>
</radio-group> </view>
</view> </radio-group>
<button class="btn-add" type="primary" @click="submit">保存</button> </view>
<button class="btn-add" type="primary" form-type="submit">保存</button>
</form>
</view> </view>
</template> </template>
...@@ -39,11 +41,6 @@ ...@@ -39,11 +41,6 @@
data() { data() {
return { return {
collection: COLLECTION_NAME, collection: COLLECTION_NAME,
username: "",
mobile: "",
gender: "",
comment: "",
email: "",
genderList: GenderList as GenderType[], genderList: GenderList as GenderType[],
$uniCloudElement: null as UniCloudDBElement | null $uniCloudElement: null as UniCloudDBElement | null
} }
...@@ -52,19 +49,14 @@ ...@@ -52,19 +49,14 @@
this.$uniCloudElement = this.$refs['udb'] as UniCloudDBElement this.$uniCloudElement = this.$refs['udb'] as UniCloudDBElement
}, },
methods: { methods: {
radioChange(e : RadioGroupChangeEvent) { // radioChange(e : RadioGroupChangeEvent) {
this.gender = e.detail.value // this.gender = e.detail.value
}, // },
submit() { onFormSubmit: function (e : FormSubmitEvent) {
const value = { const formData = e.detail.value
username: this.username, // TODO 待调整 <radio-group> <radio> value 属性为 any 后可省略此转换
gender: parseInt(this.gender), formData['gender'] = parseInt(formData['gender'] as string)
mobile: this.mobile, this.$uniCloudElement!.add(formData, {
comment: this.comment,
email: this.email,
};
this.$uniCloudElement!.add(value, {
showToast: false, showToast: false,
needLoading: true, needLoading: true,
loadingTitle: "正在保存...", loadingTitle: "正在保存...",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册