目录

geecg-uniapp 同源策略 数据请求 页面渲染 ui库安装(3)

一,同源策略

(1)要是没有env 需要创建一个替换成后端接口
(2)因为他封装了 先找到http请求位置 一级一级找 然后进行接口修改 都改完运行即可
(3)appUpdata 修改接口 运行即可

二,数据请求

(1)创建页面 ,定义请求方式 , 因为他这个封装过 ,所以我们只能跟固有的进行数据请求
(2)报错了我们解决一下 看完整路径我们发现我们复制多了(路径是拼接的)这个是正确的
(3)又报错了 是请求错了 所以注意一下是 post 还是 get
(4)正确的写法展示

三,ui库安装

(1)我查了文档才知道他这个是用一个需要下一个ui组件 太麻烦了 所以直接下载一个完整的
跟着教程 安装运行 : uni-app官网 (dcloud.net.cn)

(2)下载插件 地址 : uni-ui - DCloud 插件市场


四,获取后台数据 进行页面渲染

(1)代码展示
复制代码
<template>
	<view>
	<cu-custom bgColor="bg-gradual-pink" :isBack="true">
		<block slot="content">荒石管理</block>
	</cu-custom>
		<view class="uni-container">
			<uni-table border stripe emptyText="暂无更多数据" >
				<uni-tr>
					<uni-th width="150" align="center">日期</uni-th>
					<uni-th width="150" align="center">{{name}}</uni-th>
					<uni-th align="center">地址</uni-th>
					<uni-th width="204" align="center">设置</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<uni-td>{{ item.date }}</uni-td>
					<uni-td>
						<view class="name">{{ item.name }}</view>
					</uni-td>
					<uni-td align="center">{{ item.address }}</uni-td>
					<uni-td>
						<view class="uni-group">
							<button class="uni-button" size="mini" type="primary">修改</button>
							<button class="uni-button" size="mini" type="warn">删除</button>
						</view>
					</uni-td>
				</uni-tr>
			</uni-table>
			<view class="uni-pagination-box"><uni-pagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total" @change="change" /></view>
		</view>
	</view>
</template>
<script>
import tableData from './tableData.js'
export default {
	data() {
		return {
			searchVal: '',
			tableData: [],
			// 每页数据量
			pageSize: 10,
			// 当前页
			pageCurrent: 1,
			// 数据总量
			total: 0,
			loading: false,
			name:''
		}
	},
	onLoad() {
		this.selectedIndexs = []
		this.getData(1)
		
		let url = '/sabstone/smsSaBstoneWarehousing/list';
		this.$http.get(url).then(res=>{
			// console.log('结果',res)
			// console.log('结果',res.data.result.records)
			// this.name = res.data.code
			// this.name =res.data.result.records.length
			
			this.name =res.data.result.records[0].sabwOpuser
			
			console.log('结果',res.data.result.records)
				
		})
		
		
	},
	methods: {
	
		// 分页触发
		change(e) {
			this.$refs.table.clearSelection()
			this.selectedIndexs.length = 0
			this.getData(e.current)
		},
		// 搜索
		search() {
			this.getData(1, this.searchVal)
		},
		// 获取数据
		getData(pageCurrent, value = '') {
			this.loading = true
			this.pageCurrent = pageCurrent
			this.request({
				pageSize: this.pageSize,
				pageCurrent: pageCurrent,
				value: value,
				success: res => {
					// console.log('data', res);
					this.tableData = res.data
					this.total = res.total
					this.loading = false
				}
			})
		},
		// 伪request请求
		request(options) {
			const { pageSize, pageCurrent, success, value } = options
			let total = tableData.length
			let data = tableData.filter((item, index) => {
				const idx = index - (pageCurrent - 1) * pageSize
				return idx < pageSize && idx >= 0
			})
			if (value) {
				data = []
				tableData.forEach(item => {
					if (item.name.indexOf(value) !== -1) {
						data.push(item)
					}
				})
				total = data.length
			}

			setTimeout(() => {
				typeof success === 'function' &&
					success({
						data: data,
						total: total
					})
			}, 500)
		}
	}
}
</script>
<style>
/* #ifndef H5 */
/* page {
	padding-top: 85px;
} */
/* #endif */
.uni-group {
	display: flex;
	align-items: center;
}
</style>
(2)页面展示
本文是转载文章,点击查看原文
如有侵权,请联系 xyy@jishuzhan.net 删除
相关推荐
竣子好逑4 小时前
uniapp 自定义tabbar
前端·uni-app
Monly214 小时前
Uniapp:获取当前定位坐标
前端·javascript·uni-app
Monly2111 小时前
Uniapp:确认框
开发语言·javascript·uni-app
Monly2111 小时前
Uniapp:消息提示框
uni-app
大阳光男孩12 小时前
uniapp的通用页面及组件基本封装
前端·javascript·uni-app
老李不敲代码18 小时前
榕壹云无人共享系统:基于SpringBoot+MySQL+UniApp的物联网共享解决方案
spring boot·物联网·mysql·微信小程序·uni-app·软件需求
—Qeyser20 小时前
用 Deepseek 写的uniapp血型遗传查询工具
前端·javascript·ai·chatgpt·uni-app·deepseek
小满blue20 小时前
uniapp实现目录树效果,异步加载数据
前端·uni-app
Monly2120 小时前
Uniapp: 大纲
uni-app
Z编程1 天前
uniapp实现H5页面麦克风权限获取与录音功能
uni-app