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);
};
相关推荐
日更嵌入式的打工仔11 分钟前
嵌入式系统设计师软考个人笔记<1>
笔记
Freshman小白16 分钟前
《智能制造系统》网课答案
学习·答案·网课答案
副露のmagic38 分钟前
更弱智的算法学习 day34
python·学习
写点什么呢1 小时前
AD21安装激活
学习
wdfk_prog2 小时前
[Linux]学习笔记系列 -- bits
linux·笔记·学习
求梦8202 小时前
JVM学习
jvm·学习
九成宫2 小时前
计算机网络期末复习——第4章:网络层 Part One
网络·笔记·计算机网络·软件工程
星火开发设计2 小时前
C++ multiset 全面解析与实战指南
开发语言·数据结构·c++·学习·set·知识
shuangrenlong2 小时前
音乐app笔记
笔记
am心2 小时前
学习笔记-菜品接口-菜品分页查询
笔记·学习