uniapp 学习笔记

VUE 学习笔记

布局

html 复制代码
横向布局
<style>
H(){
display: flex;//创建 布局管理器
flex-direction: row; //方向 row垂直
flex-wrap: wrap;//显示不下是否换行
}

//居中
.center(){
    display:flex; 
		justify-content: center;//垂直居中 竖向
		align-items: center;//水平居中 横向
}

.border{
		border:2rpx solid red;//边框&颜色
		border-radius: 50rpx;//圆角
		background-color: white;//背景色
		box-shadow: 8rpx 8rpx 8rpx 0rpx red  //阴影 x偏移 Y偏移 半径 扩展宽度 颜色
	}

</style>

list用法 如果item.name 不生效 换成 item"name"

html 复制代码
<view v-for="(item,i) in list" :key="i" @click="itemOnClick(i)">
<image style="height: 20rpx;width: 20rpx;" :src="item.icon"></image>
<view style="font-size: 34rpx; color: white" >  索引值:{{item.name}}</view>
					<view style="font-size: 34rpx; color: white" >  索引值:{{item.title}}</view>
</view>
export default {
		data() { 
			return {
				title: 'Hello',
				list:[{
					id:0,
					name:"111",
					title:"测试标题111"
				},
				{
					id:1,
					name:"222",
					title:"测试标题222"
				},
				{
					id:3,
					name:"333",
					title:"测试标题333"
				}
				]
			}
			
		}

组件的引入

import 别名 from '地址'

components:{

别名

}

view的创建和移除 v-if="" true 创建 false 移除

html 复制代码
<template>

    <indexs v-if="true"></indexs>//v-if 控制是否创建

</template>
<script>
	import indexs from '../index.vue'
	components: {
			indexs
		}
</script>

view的显示和隐藏 v-show ="" true 显示 false 隐藏

html 复制代码
<template>

    <indexs v-show="true"></indexs>//v-show 控制是否显示

</template>
<script>
	import indexs from '../index.vue'
	components: {
			indexs
		}
</script>

输入框 input

html 复制代码
<input password="true"  placeholder="请输入密码" v-model="userPwd">
</input>

数据存储

html 复制代码
<script>
mounted(){//页面首次进来
   uni.setStorageSync("userName",this.userName);//同步存储数据
			this.userName = uni.getStorageSync("userName");//同步获取数据
			this.userPwd = uni.getStorageSync("userPwd");
		}
</script>

网络请求 UNIApp

地址('https://blog.csdn.net/Spy003/article/details/130979354')

java 复制代码
const BASE_URL = 'https://用你自己的url替换'; // 设置基本请求 URL
 
const requestInterceptor = (config) => {
    // 添加请求拦截逻辑
    // 在这里可以对请求进行处理,例如添加请求头、签名等
    config.header = {
        ...config.header
    };
    return config;
};
 
const responseInterceptor = (response) => {
    // 添加响应拦截逻辑
    // 在这里可以对响应进行处理,例如处理错误码、数据解析等
    if (response.statusCode === 200) {
        return response.data;
    } else {
        throw new Error('Request failed with status code ' + response.statusCode);
    }
};
 
 
const request = (config) => {
    const requestConfig = {
        ...config,
        header: requestInterceptor(config).header,
        url: BASE_URL + config.url,
    };
 
    return new Promise((resolve, reject) => {
        uni.request({
            ...requestConfig,
            success: (res) => {
                try {
                    const responseData = responseInterceptor(res);
                    resolve(responseData);
                } catch (error) {
                    reject(error);
                }
            },
            fail: (err) => {
                reject(err);
            },
        });
    });
};
 
export const get = (url, params = {}) => {
    const config = {
        url,
        method: 'GET',
        data: params,
    };
 
    return request(config);
};
 
export const post = (url, data = {}) => {
    const config = {
        url,
        method: 'POST',
        data,
    };
 
    return request(config);
};
相关推荐
me8327 分钟前
【AI面试】大模型面试60问(面试速记+详解)
人工智能·学习·ai
CHHH_HHH14 分钟前
【C++】哈希表原理与实战:从冲突解决到性能优化
开发语言·数据结构·c++·学习·算法·哈希算法·散列表
Cloud_Shy61814 分钟前
解读《Effective Python 3rd Edition》:从练气到老魔(第七章 Item 48 - 50)
开发语言·人工智能·笔记·python·microsoft·学习方法
秋雨梧桐叶落莳17 分钟前
iOS——QQ音乐仿写项目总结
学习·macos·ui·ios·mvc·objective-c·xcode
gg1593572846039 分钟前
Uni-app跨平台开发全解课程:从零基础到企业级多端落地实战
vue.js·uni-app
编程版小新43 分钟前
Day1:体验产品,以画图方式梳理用户操作和管理员操作
学习
yang)1 小时前
jesd204B应用笔记
网络·笔记
三品吉他手会点灯2 小时前
STM32F103 学习笔记-24-I2C-读写EEPROM(第2节)-I2C协议层介绍
笔记·stm32·学习
z200509302 小时前
【C++学习】C++ 类型转换深度解析:从 C 风格缺陷到 C++ 四种安全转换的思想内核
c语言·c++·学习
三品吉他手会点灯2 小时前
STM32F103 学习笔记-24-I2C-读写EEPROM(第3节)-STM32的I2C框图详解
笔记·stm32·学习