uniapp学习之路

这篇具有很好参考价值的文章主要介绍了uniapp学习之路。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1. 下载HBuilderX

https://www.dcloud.io/hbuilderx.html?ivk_sa=1024320u

2. 下载uView初始框架

https://ext.dcloud.net.cn/plugin?id=1593

3. 开始学习

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

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

2.获取屏幕高度和宽度

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 发送请求

// 插件市场安装
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

<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>

uniapp学习之路,uni-app,学习,前端文章来源地址https://www.toymoban.com/news/detail-772592.html

到了这里,关于uniapp学习之路的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • UNI-APP 人脸识别分析及实现(前端)

    实现流程: 1、打开摄像头——自动读取照片——传输给后端——后端交由第三发或自主开发来识别——返回结果(相识度比) 2、打开摄像头——自动读取视频——传输给后端——后端通过解析视频,截取图片交由第三发或自主开发来识别——返回结果(相识度比) 通过分

    2023年04月08日
    浏览(15)
  • 【uni-app教程】四、UniAPP 路由配置及页面跳转

    uni-app 页面路由为框架统一管理,开发者需要在pages.json里配置每个路由页面的路径及页面样式。类似小程序在 app.json 中配置页面路由一样。所以 uni-app 的路由用法与 Vue Router 不同,如仍希望采用 Vue Router 方式管理路由,可在插件市场搜索 Vue-Router。 uni-app 有两种页面路由跳转

    2024年01月16日
    浏览(12)
  • 【UniApp】-uni-app-项目实战页面布局(苹果计算器)

    【UniApp】-uni-app-项目实战页面布局(苹果计算器)

    经过前面的文章介绍,基本上 UniApp 的内容就介绍完毕了 那么从本文开始,我们就开始进行一个项目的实战 这次做的项目是苹果计算器,这个项目的难度不是很大,但是也不是很简单,适合练手 打开 HBuilderX,点击左上角 文件 - 新建 - 项目 : 项目创建完毕之后,首先来分析

    2024年02月04日
    浏览(45)
  • uni-app小程序实现音频播放,uniapp播放录音,uniapp简单实现播放录音

    uni-app小程序实现音频播放,uniapp播放录音,uniapp简单实现播放录音

    复制到.vue文件即可预览效果 问题 :开发者工具中.onTimeUpdate方法可能会失效! 官方参考:https://uniapp.dcloud.net.cn/api/media/audio-context.html# 其他博客参考:https://blog.csdn.net/weixin_45328705/article/details/114091301 录音实现参考 :https://blog.csdn.net/weixin_43992507/article/details/129857780

    2024年02月12日
    浏览(116)
  • #Uniapp:uni-app中vue2生命周期--11个

    uni-app中vue2生命周期 生命周期钩子 描述 H5 App端 小程序 说明 beforeCreate 在实例初始化之后被调用 详情 √ √ √ created 在实例创建完成后被立即调用 详情 √ √ √ beforeMount 在挂载开始之前被调用 详情 √ √ √ mounted 挂载到实例上去之后调用 详情 注意:此处并不能确定子组件

    2024年02月02日
    浏览(44)
  • 前端vue uni-app自定义精美海报生成组件

    前端vue uni-app自定义精美海报生成组件

    在当前技术飞速发展的时代,软件开发的复杂度也在不断提高。传统的开发方式往往将一个系统做成整块应用,一个小的改动或者一个小功能的增加都可能引起整体逻辑的修改,从而造成牵一发而动全身的情况。为了解决这个问题,组件化开发逐渐成为了一种趋势。通过组件

    2024年02月14日
    浏览(15)
  • uni-app前端H5页面底部内容被tabbar遮挡

    uni-app前端H5页面底部内容被tabbar遮挡

    在用uniapp写小程序的时候,底部有一部分内容没显示出来,被底部的tabbar遮挡住了 给最外部的view设置样式 padding-bottom: var(--window-bottom) ,如下 参考1 参考2 使用 uni-app 框架开发的一个项目,发现 H5 端页面底部的内容被导航栏(Tabbar)遮挡,小程序端可以正常显示。 查阅资料

    2024年02月04日
    浏览(12)
  • 【uni-app】【Android studio】手把手教你运行uniapp项目到Android App

    【uni-app】【Android studio】手把手教你运行uniapp项目到Android App

    选择运行到Android App基座 选择运行项目 1、连接手机,在手机上选择 传输文件。 2、打开 设置 - 关于本机 - 版本信息 -连续点击4-5次 版本号 ,输入手机密码,系统就进入了开发者模式。 3、 设置 其他设置 开发者选项 打开 开发者选项 打开 USB调试 。 4、回到Hbuilder,点击刷新

    2024年02月09日
    浏览(16)
  • 前端vue uni-app仿美团下拉框下拉筛选组件

    前端vue uni-app仿美团下拉框下拉筛选组件

    在前端Web开发中,下拉筛选功能是一种非常常见的交互方式,它可以帮助用户快速选择所需的选项。本文将介绍如何利用Vue.js和uni-app框架来实现一个高效的下拉筛选功能。通过使用这两个强大的前端框架,我们可以轻松地创建具有响应式用户操作的下拉筛选组件。 首先,我

    2024年02月09日
    浏览(13)
  • 【Uni-App】uniapp使用uview实现弹出键盘输入密码/验证码功能

    【Uni-App】uniapp使用uview实现弹出键盘输入密码/验证码功能

    组件使用的是uview组件,Keyboard 键盘和MessageInput 验证码输入两个组件配合使用。 通过mode参数定义键盘的类型,v-model绑定一个值为布尔值的变量,我绑定的是showKeyboard变量,控制键盘的弹出与收起; mode = number (默认值)为数字键盘,此时顶部工具条中间的提示文字为\\\"数字键盘

    2023年04月16日
    浏览(47)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包