两个部分弄了很久,记录过程:

request前后端交互

1.需要用到uni.request,记得先npm下载request(自己因为一开始没有下载就写代码而折腾了好久也没有成功发送请求)和uview-ui

自己现在下载了的依赖项:

下载了以后main.js:
import uView from “uview-ui”;
Vue.use(uView);
目录:

pages:

{"easycom": {"^u-(.*)": "uview-ui/components/u-$1/u-$1.vue"},"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages{"path": "pages/index/index","style": {"navigationBarTitleText": "一键洗涤"}},{"path": "pages/js/index","style": {"navigationBarTitleText": "设置"}},{"path": "pages/template/index","style": {"navigationBarTitleText": "数据查看"}},{"path": "pages/test/test","style": {"navigationBarTitleText": "测试"}}],"globalStyle": {"navigationBarTextStyle": "black","navigationBarTitleText": "uni-app","navigationBarBackgroundColor": "#F8F8F8","backgroundColor": "#F8F8F8"},"tabBar": {"color": "#909399","selectedColor": "#303133","backgroundColor": "#FFFFFF","borderStyle": "black","list": [{"pagePath": "pages/index/index","iconPath": "static/uview/example/component.png","selectedIconPath": "static/uview/example/component_select.png","text": "组件"},{"pagePath": "pages/js/index","iconPath": "static/uview/example/js.png","selectedIconPath": "static/uview/example/js_select.png","text": "工具"},{"pagePath": "pages/template/index","iconPath": "static/uview/example/template.png","selectedIconPath": "static/uview/example/template_select.png","text": "模板"}]}}

接收后端数据:

 <view v-for="(user,index) in users" :key="index"><view style="color: #71D5A1;"><u-icon name="clock" color="#2979ff" size="28"></u-icon>{{user.time}}日清洗时长:{{user.lasttime}}分钟</view><view><u-icon name="clock-fill" color="#2979ff" size="28"></u-icon>总清洗时间:{{user.alltime}}</view><hr></view><image class="logo" src="/static/wa2.png"></image><view class="text-area"><text class="title">{{title}}</text></view><script>export default {data() {return {users:[],title: '历史清洗记录',tabbar: '',list1: [{text: '水量耗费记录',color: 'blue',fontSize: 28,subText: '查看'}, {text: '清洗时间记录',color: 'green',fontSize: 28,subText: '查看'}, {text: '其他情况反馈' ,color: 'red',fontSize: 28,subText: '查看'}],show: false}},onLoad() {this.getUsers();this.tabbar = [{iconPath: "/static/uview/example/component.png",selectedIconPath: "/static/uview/example/component_select.png",text: '一键洗碗',count: 2,isDot: true,pagePath: "/pages/index/index"},{iconPath: "/static/uview/example/js.png",selectedIconPath: "/static/uview/example/js_select.png",text: '机器参数设置',midButton: true,pagePath: "/pages/js/index"},{iconPath: "/static/uview/example/template.png",selectedIconPath: "/static/wa.png",text: '历史清洗记录',pagePath: "/pages/template/index"},]},methods:{getUsers: function() {var _this= this;// 详见官网:https://uniapp.dcloud.io/api/request/requestuni.request({url:'http://localhost:9000/wash',method: 'GET',success: res => {_this.users = res.data.data;console.log(_this.users)},});console.log(22)}}}
</script><style>.content {display: flex;flex-direction: column;align-items: center;justify-content: center;}.logo {height: 400rpx;width: 600rpx;margin-top: 50rpx;margin-left: auto;margin-right: auto;margin-bottom: 50rpx;}.text-area {display: flex;justify-content: center;}.title {font-size: 36rpx;color: #8f8f94;}
</style>


后端用的是之前的springboot框架:
Mapper层:

@Mapper
public interface WashDao {@Select("select id,lasttime,alltime,times,average,Time from wash")List<Wash> findAll();
}

service:

public interface WahService {List<Wash> allWash();
}@Service
public class WashServiceImpl implements WahService{@AutowiredWashDao washDao;@Overridepublic List<Wash> allWash(){return washDao.findAll();}
}

controller:

@RestController
public class WashController {@Autowiredprivate WashServiceImpl washService;@GetMapping("/wash")public ApiResult getWsah(){List<Wash>res = washService.allWash();return ApiResultHandler.buildApiResult(200,"查询所有洗涤时间",res);}
}

连接数据库并启动后端
注意:用真机调试的话localhost换成局域网下的ip地址
用ipconfig -all查看ip地址

使用swiper:

<view class="u-swiper-wrap" :style="{borderRadius: `${borderRadius}rpx`}"><swiper :current="elCurrent" @change="change" @animationfinish="animationfinish" :interval="interval" :circular="circular" :duration="duration" :autoplay="autoplay":previous-margin="effect3d ? effect3dPreviousMargin + 'rpx' : '0'" :next-margin="effect3d ? effect3dPreviousMargin + 'rpx' : '0'":style="{height: height + 'rpx',backgroundColor: bgColor}"><swiper-item class="u-swiper-item" v-for="(item, index) in list" :key="index"><view class="u-list-image-wrap" @tap.stop.prevent="listClick(index)" :class="[uCurrent != index ? 'u-list-scale' : '']" :style="{borderRadius: `${borderRadius}rpx`,transform: effect3d && uCurrent != index ? 'scaleY(0.9)' : 'scaleY(1)',margin: effect3d && uCurrent != index ? '0 20rpx' : 0,}"><image class="u-swiper-image" :src="item[name] || item" :mode="imgMode"></image><view v-if="title && item.title" class="u-swiper-title u-line-1" :style="[{'padding-bottom': titlePaddingBottom}, titleStyle]">{{ item.title }}</view></view></swiper-item></swiper><view class="u-swiper-indicator" :style="{top: indicatorPos == 'topLeft' || indicatorPos == 'topCenter' || indicatorPos == 'topRight' ? '12rpx' : 'auto',bottom: indicatorPos == 'bottomLeft' || indicatorPos == 'bottomCenter' || indicatorPos == 'bottomRight' ? '12rpx' : 'auto',justifyContent: justifyContent,padding: `0 ${effect3d ? '74rpx' : '24rpx'}`}"><block v-if="mode == 'rect'"><view class="u-indicator-item-rect" :class="{ 'u-indicator-item-rect-active': index == uCurrent }" v-for="(item, index) in list":key="index"></view></block><block v-if="mode == 'dot'"><view class="u-indicator-item-dot" :class="{ 'u-indicator-item-dot-active': index == uCurrent }" v-for="(item, index) in list":key="index"></view></block><block v-if="mode == 'round'"><view class="u-indicator-item-round" :class="{ 'u-indicator-item-round-active': index == uCurrent }" v-for="(item, index) in list":key="index"></view></block><block v-if="mode == 'number'"><view class="u-indicator-item-number">{{ uCurrent + 1 }}/{{ list.length }}</view></block></view></view>
<script>import swiper from "swiper";export default {props: {// 轮播图的数据,格式如:[{image: 'xxxx', title: 'xxxx'},{image: 'yyyy', title: 'yyyy'}],其中title字段可选list: {type: Array,default () {return [{image: '../../static/wa2.png'},{image: '../../static/wa3.png'},{image: '../../static/wa4.png'},{image: '../../static/wa9.png'}];}},// 是否显示title标题title: {type: Boolean,default: false},// 用户自定义的指示器的样式indicator: {type: Object,default () {return {};}},// 圆角值borderRadius: {type: [Number, String],default: 8},// 隔多久自动切换interval: {type: [String, Number],default: 3000},// 指示器的模式,rect|dot|number|roundmode: {type: String,default: 'round'},// list的高度,单位rpxheight: {type: [Number, String],default: 900},// 指示器的位置,topLeft|topCenter|topRight|bottomLeft|bottomCenter|bottomRightindicatorPos: {type: String,default: 'bottomCenter'},// 是否开启缩放效果effect3d: {type: Boolean,default: false},// 3D模式的情况下,激活item与前后item之间的距离,单位rpxeffect3dPreviousMargin: {type: [Number, String],default: 50},// 是否自动播放autoplay: {type: Boolean,default: true},// 自动轮播时间间隔,单位msduration: {type: [Number, String],default: 500},// 是否衔接滑动,即到最后一张时接着滑动,是否自动切换到第一张circular: {type: Boolean,default: true},// 图片的裁剪模式 imgMode: {type: String,default: 'aspectFill'},// 从list数组中读取的图片的属性名name: {type: String,default: 'image'},// 背景颜色bgColor: {type: String,default: '#f3f4f6'},// 初始化时,默认显示第几项current: {type: [Number, String],default: 0},// 标题的样式,对象形式titleStyle: {type: Object,default() {return {}}}},watch: {// 如果外部的list发生变化,判断长度是否被修改,如果前后长度不一致,重置uCurrent值,避免溢出list(nVal, oVal) {if(nVal.length !== oVal.length) this.uCurrent = 0;},// 监听外部current的变化,实时修改内部依赖于此测uCurrent值,如果更新了current,而不是更新uCurrent,// 就会错乱,因为指示器是依赖于uCurrent的current(n) {this.uCurrent = n;}},data() {return {uCurrent: this.current ,title: 'Hello Intelligent wash',tabbar: '',}},computed: {justifyContent() {if (this.indicatorPos == 'topLeft' || this.indicatorPos == 'bottomLeft') return 'flex-start';if (this.indicatorPos == 'topCenter' || this.indicatorPos == 'bottomCenter') return 'center';if (this.indicatorPos == 'topRight' || this.indicatorPos == 'bottomRight') return 'flex-end';},titlePaddingBottom() {let tmp = 0;if (this.mode == 'none') return '12rpx';if (['bottomLeft', 'bottomCenter', 'bottomRight'].indexOf(this.indicatorPos) >= 0 && this.mode == 'number') {tmp = '60rpx';} else if (['bottomLeft', 'bottomCenter', 'bottomRight'].indexOf(this.indicatorPos) >= 0 && this.mode != 'number') {tmp = '40rpx';} else {tmp = '12rpx';}return tmp;},// 因为uni的swiper组件的current参数只接受Number类型,这里做一个转换elCurrent() {return Number(this.current);}},methods: {// 按钮点击listClick(index) {this.$emit('click', index);},change(e) {let current = e.detail.current;this.uCurrent = current;// 发出change事件,表示当前自动切换的index,从0开始this.$emit('change', current);},// 头条小程序不支持animationfinish事件,改由change事件// 暂不监听此事件,因为不再给swiper绑定uCurrent属性animationfinish(e) {// #ifndef MP-TOUTIAO// this.uCurrent = e.detail.current;// #endif}}}
</script>

效果:

附:

引入iview:
按需引用 #
借助插件 babel-plugin-import可以实现按需加载组件,减少文件体积。首先安装,并在文件 .babelrc 中配置:

npm install babel-plugin-import --save-dev

// .babelrc
{
“plugins”: [[“import”, {
“libraryName”: “view-design”,
“libraryDirectory”: “src/components”
}]]
}
然后这样按需引入组件,就可以减小体积了:

import { Button, Table } from ‘view-design’;
Vue.component(‘Button’, Button);
Vue.component(‘Table’, Table);
特别提醒 #
按需引用仍然需要导入样式,即在 main.js 或根组件执行 import ‘view-design/dist/styles/iview.css’;
组件使用规范 #
使用:prop传递数据格式为 数字、布尔值或函数时,必须带:(兼容String除外,具体看组件文档),比如:

Correct usage:

Incorrect usage:

在非 template/render 模式下(例如使用 CDN 引用时),组件名要分隔,例如 DatePicker 必须要写成 date-picker。

以下组件,在非 template/render 模式下,需要加前缀 i-:

Button: i-button
Col: i-col
Table: i-table
Input: i-input
Form: i-form
Menu: i-menu
Select: i-select
Option: i-option
Progress: i-progress
Time: i-time
以下组件,在所有模式下,必须加前缀 i-,除非使用 iview-loader:

Switch: i-switch
Circle: i-circle

【项目】uniapp前端接收后端springboot数据并渲染到界面+使用swiper和uView相关推荐

  1. python的前端和后端_前端与后端的数据交互(jquery ajax+python flask)

    前端与后端的数据交互,最常用的就是GET.POST,比较常用的用法是:提交表单数据到后端,后端返回json 前端的数据发送与接收 1)提交表单数据 2)提交JSON数据 后端的数据接收与响应 1)接收 ...

  2. python后端数据发送到前端_前端与后端的数据交互(jquery ajax+python flask)

    前端与后端的数据交互,最常用的就是GET.POST,比较常用的用法是:提交表单数据到后端,后端返回json 前端的数据发送与接收 1)提交表单数据 2)提交JSON数据 后端的数据接收与响应 1)接收 ...

  3. 后端处理数据保存请求流程multer+ajax 数据库添加数据 前端与后端的数据联通 在business_list 页面进行数据处理 @stage3---week3--day4

    后端处理 基础流程 $ npx be_app -e 快速构建项目骨架 $ yarn 安装依赖包 修改 package.json {"name": "be-app" ...

  4. python后端与前端数据交互_前端与后端的数据交互(jquery ajax+python flask)

    前端与后端的数据交互,最常用的就是GET.POST,比较常用的用法是:提交表单数据到后端,后端返回json 前端的数据发送与接收 1)提交表单数据 2)提交JSON数据 后端的数据接收与响应 1)接收 ...

  5. 前端与后端传递数据 — — JSON

    前端与后端传递数据 - - JSON 1 前端传送JSON数据给后端 1.1 application/x-www-form-urlencoded默认格式 1.1.1 通过HttpServletRequ ...

  6. 前端给后端传递数据的时候,有些后端自己可以获取到的值应该由前端传递吗?

    前端给后端传递数据的时候,有些后端自己可以获取到的值应该由前端传递吗? 场景: 1.比如我向后端传递一个学生做的试卷. 2.后端需要我把学生的答案和标准答案(在获取试卷的时候给我的,我知道很扯淡)同时 ...

  7. SSM-物流管理常见问题4 前端向后端传递数据

    前端向后端传递数据现在有一个很常用的方法就是使用ajax, 还有一个方法 <li><a href="${APP_PATH }/user/list.do?pageIndex= ...

  8. 【前后端记录】前端接收后端数据并用div元素渲染 ,mybatis修改用户数据。

    一个很小的点但折腾了很久,为了把后端的数据解析出来查了很多资料,原功能是想显示登录的用户信息,但进行token认证和security整合过于麻烦,直接建了一个数据表来显示至页面. 效果是这样: 当然, ...

  9. vue 项目 前端 模拟后端接口数据(vue2,vue3)

    项目中或者平常自己创建demo的过程中,往往需要后端配合,但是有时候没有后端,又需要数据,此时就展示了我们前端的强大之处,自己模拟后端接口数据. 如果自定义一个模拟后端数据, 首先创建一个文件夹放置后 ...

最新文章

  1. ios Standard Framework和Umbrella Framework
  2. fedora-10-i386下华为联网问题
  3. 基于Yolo-V3对卫星图像进行储油罐容积占用率的研究
  4. 如何生成存储器配置文件?
  5. 剑指offer:二维数组中的查找
  6. C++学习——类的初始化
  7. linux wegt克隆网站,linux利用wget命令备份网站(镜像拷贝)
  8. mysql 不认的字符串_mysql 判断字符串是否为其他字符串的子集
  9. 小程序 发送模板消息的功能实现
  10. 计算机基础知识问卷,计算机基础知识情况问卷调查
  11. apr_thread使用内存之谜
  12. 红米手机开启---开发者选项方法
  13. 华为往事(十一)---华为的“中南海”
  14. 渲染是不是很费电脑,云渲染对电脑的要求高吗?
  15. 推荐低保真原型设计软件 Balsamiq Mockup
  16. OpenCV中图像特征提取与描述
  17. 汤润芝:我为什么要投资美股?(转)
  18. 云队友丨直面真问题,找到根本解:如何有效解决问题?
  19. Windows8.1
  20. APS计划排产软件实现新能源汽车企业人员结构优化

热门文章

  1. python序列类型唯一的映射类型_python2.x学习笔记(8)-映射和集合类型
  2. php补充 扩展,php补充安装扩展支持
  3. 栈和队列的Java实现_栈和队列的java简单实现
  4. 我为什么重新做起了公众号?
  5. 五十、微信小程序云开发中的云数据库
  6. 七十、SpringBoot整合 Druid数据源
  7. 用jiebaR分析比特币的文章
  8. 从频率角度理解为什么深度可以加速神经网络的训练
  9. Self-Orthogonality Module:一个即插即用的核正交化模块
  10. SIGIR 2019 开源论文 | 用户注意力指导的多模态对话系统