当前位置:   article > 正文

uni-app引入vant表单(附源码)_uniapp小程序vant表单

uniapp小程序vant表单
新建项目

下载安装vant
npm i vant

main.js引入
  1. import { Form } from 'vant';
  2. import { Field } from 'vant';
  3. Vue.use(Form);
  4. Vue.use(Field);

代码引入
  1. <van-form @submit="onSubmit">
  2. <van-field
  3. class="rePwd"
  4. v-model="username"
  5. name="请输入原密码"
  6. label="原密码"
  7. placeholder="请输入原登录密码"
  8. :rules="[{ required: true, message: '请输入原密码' }]"
  9. />
  10. <van-field
  11. class="rePwd"
  12. v-model="password"
  13. type="password"
  14. name="请输入新密码"
  15. label="新密码"
  16. placeholder="请输入新的密码"
  17. :rules="[{ required: true, message: '请输入新密码' }]"
  18. />
  19. <van-field
  20. class="rePwd"
  21. v-model="password"
  22. type="password"
  23. name="请确认新密码"
  24. label="确认密码"
  25. placeholder="请再次输入新的密码"
  26. :rules="[{ required: true, message: '请确认新密码' }]"
  27. />
  28. <div style="margin: 16px;">
  29. <van-button class="repwdBtn" round block type="info" native-type="submit">确定</van-button>
  30. </div>
  31. </van-form>

@import 'vant/lib/index.css'

这个是在App.vue里面引入的,样式的话根据自己的项目添加,主要是引入css文件

运行

这是全局样式,如果要修改样式,可以重新起类名写样式

message里面信息也可以删掉

完整代码

  1. <template>
  2. <view class="content">
  3. <van-form @submit="onSubmit">
  4. <van-field
  5. class="rePwd"
  6. v-model="username"
  7. name="请输入原密码"
  8. label="原密码"
  9. placeholder="请输入原登录密码"
  10. :rules="[{ required: true, message: '' }]"
  11. />
  12. <van-field
  13. class="rePwd"
  14. v-model="password"
  15. type="password"
  16. name="请输入新密码"
  17. label="新密码"
  18. placeholder="请输入新的密码"
  19. :rules="[{ required: true, message: '' }]"
  20. />
  21. <van-field
  22. class="rePwd"
  23. v-model="password"
  24. type="password"
  25. name="请确认新密码"
  26. label="确认密码"
  27. placeholder="请再次输入新的密码"
  28. :rules="[{ required: true, message: '' }]"
  29. />
  30. <div style="margin: 16px;">
  31. <van-button class="repwdBtn" round block type="info" native-type="submit">确定</van-button>
  32. </div>
  33. </van-form>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. username: '',
  41. password: '',
  42. }
  43. },
  44. methods: {
  45. onSubmit(values) {
  46. console.log('submit', values)
  47. }
  48. }
  49. }
  50. </script>
  51. <style>
  52. .rePwd{
  53. padding: 16px 15px;
  54. font-size: 15px;
  55. }
  56. .repwdBtn{
  57. border-radius: 3px;
  58. background: #357FFF;
  59. }
  60. </style

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/823121
推荐阅读
相关标签
  

闽ICP备14008679号