当前位置:   article > 正文

手机/移动端的UI框架-Vant和NutUI_移动端ui框架

移动端ui框架

下面推荐2款手机/移动端的UI框架

其实还有很多的框架,各个大厂都有UI框架。目前,找来找去,只有腾讯的移动端是setup语法写的TDesign,其他大厂,虽然都是VUE3写的,但是都还未改成setup的语法,而且,腾讯的版本也比较新,所以暂时不做案例了。我们使用成熟的UI框架Vant和NutUI来演示。其中京东的NutUI组件,还有小程序组件。

目录

一、Vant

二、NutUI


一、Vant

官网,Vant 4 - A lightweight, customizable Vue UI library for mobile web apps.,多的不说了,可以看官网介绍,下面我们直接创建程序。

1. 我们使用HBuilder X创建一个正常的程序

2.命令安装

npm i vant

安装完成标志

3.这里的mian.js不需要修改,和很多其他组件不一样

  1. import { createApp } from 'vue'
  2. import App from './App.vue'
  3. createApp(App).mount('#app')

4.因为用的是vite创建的项目,所以修改vite.config.js

  1. import vue from '@vitejs/plugin-vue'
  2. import Components from 'unplugin-vue-components/vite'
  3. import {
  4. VantResolver
  5. } from 'unplugin-vue-components/resolvers'
  6. export default {
  7. plugins: [
  8. vue(),
  9. Components({
  10. resolvers: [VantResolver()]
  11. })
  12. ]
  13. }

5.命令安装插件,否则报错

npm i unplugin-vue-components -D
npm i less

成功标志

6.HelloWorld.vue中引用组件的功能

  1. <template>
  2. <van-form @submit="onSubmit">
  3. <van-cell-group inset>
  4. <van-field v-model="username" name="用户名" label="用户名" placeholder="用户名"
  5. :rules="[{ required: true, message: '请填写用户名' }]" />
  6. <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码"
  7. :rules="[{ required: true, message: '请填写密码' }]" />
  8. </van-cell-group>
  9. <div style="margin: 16px;">
  10. <van-button round block type="primary" native-type="submit">
  11. 提交
  12. </van-button>
  13. </div>
  14. </van-form>
  15. <van-form @submit="onSubmit">
  16. <van-cell-group inset>
  17. <van-field v-model="username" name="用户名" label="用户名" placeholder="用户名"
  18. :rules="[{ required: true, message: '请填写用户名' }]" />
  19. <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码"
  20. :rules="[{ required: true, message: '请填写密码' }]" />
  21. </van-cell-group>
  22. <div style="margin: 16px;">
  23. <van-button round block type="primary" native-type="submit">
  24. 提交
  25. </van-button>
  26. </div>
  27. </van-form>
  28. <van-form @submit="onSubmit">
  29. <van-cell-group inset>
  30. <van-field v-model="username" name="用户名" label="用户名" placeholder="用户名"
  31. :rules="[{ required: true, message: '请填写用户名' }]" />
  32. <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码"
  33. :rules="[{ required: true, message: '请填写密码' }]" />
  34. </van-cell-group>
  35. <div style="margin: 16px;">
  36. <van-button round block type="primary" native-type="submit">
  37. 提交
  38. </van-button>
  39. </div>
  40. </van-form>
  41. <van-form @submit="onSubmit">
  42. <van-cell-group inset>
  43. <van-field v-model="username" name="用户名" label="用户名" placeholder="用户名"
  44. :rules="[{ required: true, message: '请填写用户名' }]" />
  45. <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码"
  46. :rules="[{ required: true, message: '请填写密码' }]" />
  47. </van-cell-group>
  48. <div style="margin: 16px;">
  49. <van-button round block type="primary" native-type="submit">
  50. 提交
  51. </van-button>
  52. </div>
  53. </van-form>
  54. <van-form @submit="onSubmit">
  55. <van-cell-group inset>
  56. <van-field v-model="username" name="用户名" label="用户名" placeholder="用户名"
  57. :rules="[{ required: true, message: '请填写用户名' }]" />
  58. <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码"
  59. :rules="[{ required: true, message: '请填写密码' }]" />
  60. </van-cell-group>
  61. <div style="margin: 16px;">
  62. <van-button round block type="primary" native-type="submit">
  63. 提交
  64. </van-button>
  65. </div>
  66. </van-form>
  67. <van-form @submit="onSubmit">
  68. <van-cell-group inset>
  69. <van-field v-model="username" name="用户名" label="用户名" placeholder="用户名"
  70. :rules="[{ required: true, message: '请填写用户名' }]" />
  71. <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码"
  72. :rules="[{ required: true, message: '请填写密码' }]" />
  73. </van-cell-group>
  74. <div style="margin: 16px;">
  75. <van-button round block type="primary" native-type="submit">
  76. 提交
  77. </van-button>
  78. </div>
  79. </van-form>
  80. <van-form @submit="onSubmit">
  81. <van-cell-group inset>
  82. <van-field v-model="username" name="用户名" label="用户名" placeholder="用户名"
  83. :rules="[{ required: true, message: '请填写用户名' }]" />
  84. <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码"
  85. :rules="[{ required: true, message: '请填写密码' }]" />
  86. </van-cell-group>
  87. <div style="margin: 16px;">
  88. <van-button round block type="primary" native-type="submit">
  89. 提交
  90. </van-button>
  91. </div>
  92. </van-form>
  93. <van-form @submit="onSubmit">
  94. <van-cell-group inset>
  95. <van-field v-model="username" name="用户名" label="用户名" placeholder="用户名"
  96. :rules="[{ required: true, message: '请填写用户名' }]" />
  97. <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码"
  98. :rules="[{ required: true, message: '请填写密码' }]" />
  99. </van-cell-group>
  100. <div style="margin: 16px;">
  101. <van-button round block type="primary" native-type="submit">
  102. 提交
  103. </van-button>
  104. </div>
  105. </van-form>
  106. <van-tabbar v-model="active">
  107. <van-tabbar-item icon="home-o">标签</van-tabbar-item>
  108. <van-tabbar-item icon="search">标签</van-tabbar-item>
  109. <van-tabbar-item icon="friends-o">标签</van-tabbar-item>
  110. <van-tabbar-item icon="setting-o">标签</van-tabbar-item>
  111. </van-tabbar>
  112. </template>
  113. <script>
  114. export default {
  115. data() {
  116. return {
  117. goods: {
  118. title: "美国伽力果213(约680g/3个)",
  119. price: 2680,
  120. express: "免运费",
  121. remain: 19,
  122. thumb: [
  123. "https://img.yzcdn.cn/public_files/2017/10/24/e5a5a02309a41f9f5def56684808d9ae.jpeg",
  124. "https://img.yzcdn.cn/public_files/2017/10/24/1791ba14088f9c2be8c610d0a6cc0f93.jpeg",
  125. ],
  126. },
  127. };
  128. },
  129. methods: {
  130. formatPrice() {
  131. return "¥" + (this.goods.price / 100).toFixed(2);
  132. },
  133. onClickCart() {
  134. this.$router.push("cart");
  135. },
  136. sorry() {
  137. Toast("暂无后续逻辑~");
  138. },
  139. },
  140. };
  141. </script>
  142. <style lang="less">
  143. body {
  144. font-size: 16px;
  145. background-color: #f8f8f8;
  146. -webkit-font-smoothing: antialiased;
  147. }
  148. .goods {
  149. padding-bottom: 50px;
  150. &-swipe {
  151. img {
  152. width: 100%;
  153. display: block;
  154. }
  155. }
  156. &-title {
  157. font-size: 16px;
  158. }
  159. &-price {
  160. color: #f44;
  161. }
  162. &-express {
  163. color: #999;
  164. font-size: 12px;
  165. padding: 5px 15px;
  166. }
  167. &-cell-group {
  168. margin: 15px 0;
  169. }
  170. &-tag {
  171. margin-left: 5px;
  172. }
  173. }
  174. </style>

7.运行效果

PC端

手机端

二、NutUI

官网,NutUI - 移动端组件库,多的不说了,可以看官网介绍,下面我们直接创建程序。

1. 我们使用HBuilder X创建一个正常的程序

2. 使用命令安装

npm i @nutui/nutui

安装完成标志

 

3.main.js中,我们使用全局引入,实际开发中,为了更小的程序包,可以按需引入

  1. import {
  2. createApp
  3. } from "vue";
  4. import App from "./App.vue";
  5. import NutUI from "@nutui/nutui";
  6. import "@nutui/nutui/dist/style.css";
  7. createApp(App).use(NutUI).mount("#app");

4.因为用的是vite创建的项目,所以修改vite.config.js

  1. import {
  2. defineConfig
  3. } from 'vite'
  4. import vue from '@vitejs/plugin-vue'
  5. import Components from 'unplugin-vue-components/vite'
  6. import NutUIResolver from '@nutui/nutui/dist/resolver'
  7. // https://vitejs.dev/config/
  8. export default defineConfig({
  9. plugins: [
  10. vue(),
  11. // 开启 unplugin 插件,自动引入 NutUI 组件
  12. Components({
  13. resolvers: [NutUIResolver()]
  14. })
  15. ],
  16. // 配置全局样式变量
  17. css: {
  18. preprocessorOptions: {
  19. scss: {
  20. additionalData: '@import "@nutui/nutui/dist/styles/variables.scss";'
  21. }
  22. }
  23. }
  24. })

5.HelloWorld.vue中引用组件的功能

  1. <template>
  2. <nut-form>
  3. <nut-form-item label="姓名">
  4. <nut-input v-model="basicData.name" class="nut-input-text" placeholder="请输入姓名" type="text" />
  5. </nut-form-item>
  6. <nut-form-item label="年龄">
  7. <nut-input v-model="basicData.age" class="nut-input-text" placeholder="请输入年龄" type="text" />
  8. </nut-form-item>
  9. <nut-form-item label="联系电话">
  10. <nut-input v-model="basicData.tel" class="nut-input-text" placeholder="请输入联系电话" type="text" />
  11. </nut-form-item>
  12. <nut-form-item v-model="basicData.address" label="地址">
  13. <nut-input class="nut-input-text" placeholder="请输入地址" type="text" />
  14. </nut-form-item>
  15. <nut-form-item label="备注">
  16. <nut-textarea placeholder="请输入备注" type="text" />
  17. </nut-form-item>
  18. </nut-form>
  19. <nut-tabbar bottom safe-area-inset-bottom placeholder>
  20. <nut-tabbar-item v-for="(item,index) in List" :tab-title="item.title" :icon="item.icon"> </nut-tabbar-item>
  21. </nut-tabbar>
  22. </template>
  23. <script lang="ts">
  24. import {
  25. h,
  26. ref,
  27. reactive
  28. } from 'vue';
  29. import {
  30. Home,
  31. Category,
  32. Find,
  33. Cart,
  34. My
  35. } from '@nutui/icons-vue';
  36. export default {
  37. components: {
  38. Home,
  39. Category,
  40. Find,
  41. Cart,
  42. My
  43. },
  44. setup() {
  45. const basicData = reactive({
  46. name: '',
  47. age: '',
  48. tel: '',
  49. address: ''
  50. })
  51. const List = [{
  52. title: '标签',
  53. icon: h(Home),
  54. },
  55. {
  56. title: '标签',
  57. icon: h(Category),
  58. },
  59. {
  60. title: '标签',
  61. icon: h(Find),
  62. },
  63. {
  64. title: '标签',
  65. icon: h(Cart),
  66. },
  67. {
  68. title: '标签',
  69. icon: h(My),
  70. }
  71. ]
  72. return {
  73. List,
  74. basicData
  75. };
  76. },
  77. }
  78. </script>

6.运行效果

PC端

手机端

 源码地址:

Demo-NutUI: Demo-NutUI

https://gitee.com/602874946/demo-vant-d

本文来源:

手机/移动端的UI框架-Vant和NutUI_移动端ui框架-CSDN博客

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

闽ICP备14008679号