uniapp学习之路

uniapp 学习之路

1. 下载HBuilderX

l 复制代码
https://www.dcloud.io/hbuilderx.html?ivk_sa=1024320u

2. 下载uView初始框架

j 复制代码
https://ext.dcloud.net.cn/plugin?id=1593

3. 开始学习

1.更改页面背景色,渐变色

j 复制代码
<style>
	 page{
		  background-image: linear-gradient(to bottom, #f8f6e7 0%, #f8f6eb 25%,  #f6f5ed 50%, #f6f5f3 100%); /* 多个渐变色 */
	 }
</style>

2.获取屏幕高度和宽度

j 复制代码
uni.getSystemInfo({
  success: (res) => {
	this.screenHeight = res.windowHeight + 'px';
	this.screenWidth = res.windowWidth + 'px';
	console.log('屏幕宽度:', this.screenWidth);
	console.log('屏幕高度:', this.screenHeight);
  },
});

3.使用 gt-axios-request 发送请求

j 复制代码
// 插件市场安装
1. https://ext.dcloud.net.cn/plugin?id=5672
2. 在@/uni_modules/gt-axios-request/目录下, 安装 axios npm install
3. 修改配置 如下
(1). 修改config.js中的API接口 如下:
'@/uni_modules/gt-axios-request/js_sdk/config.js'
axios.defaults.baseURL = '你要修改的服务器地址' 

(2)、在项目的main.js文件中引入install.js 如下:
// 引入 gt-axios-request
import { install as http } from '@/uni_modules/gt-axios-request/js_sdk/install.js'
Vue.use(http)

(3). api/index.js 如下:
export const TEST_DATA = '/game/list'
export const GAME_DATA = '/game/data'

(4)、在pages文件中直接使用 如下:
import { GAME_DATA, TEST_DATA } from 'api'

receiveCMS() {
    const data = {
        "Page": 1,
        "Limit": 10
    }
    this.$http.post(TEST_DATA, data, { showLoading: true }).then(res => {
        console.log("🚀 ~ file: index.vue ~ line 33 ~ this.$http.post ~ res", res)
    })
},
async receiveCMSAsync() {
    const data = {
        "Page": 1,
        "Limit": 10
    }
    const res = await this.$http.post(TEST_DATA, data)
    console.log("🚀 ~ file: index.vue ~ line 43 ~ receiveCMSAsync ~ res", res)
},
receiveMember() {
    // 开启缓存,设置缓存时间为一个小时,缓存的模式为localStorage
    const data = {}
    this.$http.get(GAME_DATA, data).then(res => {
        console.log("🚀 ~ file: index.vue ~ line 47 ~ this.$http.get ~ res", res)
    })
},
async receiveMemberAsync() {
    // 开启缓存,设置缓存时间为一个小时,缓存的模式为localStorage
    const data = {}
    const res = await this.$http.get(GAME_DATA, data, { showLoading: true, cache: true, expires: 1000 * 60 * 60 })
    console.log("🚀 ~ file: index.vue ~ line 54 ~ receiveMemberAsync ~ res", res)
}

4.登录页demo

j 复制代码
<template>
	<view :style="{'height':screenHeight}">
		<view class="loginHead"></view>
		<view class="loginBody">
			<u-form>
			<u-row class="input1 shadow1">
				<u-input border="bottom" v-model="userName" placeholder="用户名:">
					<u-icon
					slot="prefix"
					style="margin-right: 5px;"
					type="tips"
					name="/static/login-img/u1.png">
					</u-icon>
				</u-input>
			</u-row>
			<u-row class="input1 shadow1" style="margin-bottom: 30px;">
				<u-input border="bottom" v-model="password" type="password" placeholder="密码:">
					<u-icon
					slot="prefix"
					type="tips"
					style="margin-right: 5px;"
					name="/static/login-img/lock.png">
					</u-icon>
				</u-input>
			</u-row>
			<u-row class="button1">
				<u-button shape="circle" color="#fbd878" :hairline="true" text="登录" @click="getLogin"></u-button>
			</u-row>
			<u-row class="button1">
				<u-button shape="circle" color="#fbd878":plain="true" :hairline="true" text="注册"></u-button>
			</u-row>
			</u-form>
		</view>
		<view class="loginEnd"></view>
	</view>
</template>
<script>
	import { LOGIN } from '@/api/index'
	export default {
		created() {
			// 获取屏幕高度和宽度
			this.getScreenSize()
		},
		data() {
			return {
				screenWidth: '100px',
				screenHeight: '300px',
				userName: '',
				password: ''
			}
		},
		methods: {
			getScreenSize() {
				uni.getSystemInfo({
				  success: (res) => {
					this.screenHeight = res.windowHeight + 'px';
					this.screenWidth = res.windowWidth + 'px';
					console.log('屏幕宽度:', this.screenWidth);
					console.log('屏幕高度:', this.screenHeight);
				  },
				});
			},
			getLogin() {
				const data = {
					"userName": this.userName,
					"password": this.password
				}
				this.$http.post(LOGIN, data, { showLoading: true }).then(res => {
					console.log("🚀 ~ file: index.vue ~ line 33 ~ this.$http.post ~ res", res)
				})
			}
			
		}
	}
</script>

<style>
	 page{
		  background-image: linear-gradient(to bottom, #f8f6e7 0%, #f8f6eb 25%,  #f6f5ed 50%, #f6f5f3 100%); /* 多个渐变色 */
	 }
	 .loginHead {
		 height: 20%;display: flex;
	 }
	 .loginBody {
		 height: 60%;
	 }
	 .loginEnd {
		 height: 20%;display: flex;
	 }
	 .wrap {
		padding-left: 5%;
	 }
	 .input1 {
		 background-color: white; border-radius: 12px;width: 90%;margin-left: 5%;margin-right: 5%;margin-top: 14px;
	 }
	 .shadow1 {
		box-shadow:5px 5px 10px #e6e5dc;
	 }
	 .button1 {
		width: 80%;margin-left: 10%;margin-right: 10%;margin-top: 14px;
	 }
</style>
相关推荐
明仔的阳光午后39 分钟前
React 入门 02:从单页面应用到多页面应用
前端·react.js·前端框架
.生产的驴41 分钟前
React 页面路由ReactRouter 路由跳转 参数传递 路由配置 嵌套路由
前端·javascript·react.js·前端框架·json·ecmascript·html5
非凡ghost42 分钟前
批量转双层PDF(可识别各种语言) 中文绿色版
前端·windows·pdf·计算机外设·软件需求
苏卫苏卫苏卫44 分钟前
【码源】智能无人仓库管理系统(详细码源下~基于React+TypeScript+Vite):
前端·react.js·typescript·vite·项目设计·智能无人仓库管理系统·码源
打小就很皮...44 分钟前
PDF 下载弹窗 content 区域可行性方案
前端·javascript·pdf
江苏世纪龙科技2 小时前
新能源汽车故障诊断与排除虚拟实训软件——赋能职业教育新工具
学习
Felicity_Gao4 小时前
uni-app VOD 与 COS 选型、开发笔记
前端·笔记·uni-app
兔兔爱学习兔兔爱学习5 小时前
Spring Al学习7:ImageModel
java·学习·spring
我狸才不是赔钱货5 小时前
前端技术栈全景图:从HTML到现代框架的演进之路
前端·html
百花~6 小时前
前端三剑客之一 HTML~
前端·html