uni-App development record


uni app

Development preparation:

Official document:
https://uniapp.dcloud.io/collocation/pages

Development tools
Download HBuilder X editor (official recommendation)


One, create uni-App

Create a new project
Insert picture description here
Select create project to enter the project configuration,
Insert picture description here
here you can choose according to your own needs

Second, use steps

1. Project structure

Insert picture description here

2. Document structure

Single file structure

<template>
		// html文件部分
		<view></view>
</template>

<script>
	// 引入组件
	import Card from "../../components/list-card/list-card.vue"
	export default {
		data() {
			return {
				// data数据存放地
			}
		},
		components: {
			// 引入的组件
			Card
		},
		onLoad() {
			// 小程序的生命周期函数 除此以外还有onshow onready等  
		},
		computed: {
			// vue的计算属性
		},
		methods: {
			// 所有方法都在这里
		},
		watch: {
			// vue的监听 等 大部分都可以实现
		},
	}
</script>
// 样式 可选scss less 
<style lang="scss" scoped></style>

2. Components

Insert picture description here

Structure code:

<template>
	<view class="tab">		
	</view>
</template>

<script>
export default {
	// 接收父组件的传值
	props: {
		tabList: {
			type: Array,
			default: []
		},
		tabActiveIdx: {
			type: Number,
			default: 0
		}
	},
	// 组件自己的数据
	data() {
		return {
		};
	},
	// 组件级的生命周期
	onLoad() {
	},
	// 组件级的方法
	methods: {
	}
};
</script>

<style lang="less" scoped>
</style>

Plug-in market link
https://ext.dcloud.net.cn/

Three, common problems

  1. From the development software used by uniapp, to creation, to operation, how to package code for different platforms, how to package apk, cloud package, and how to run on different terminals
    Insert picture description here

Select the project and click Release to select the packaging configuration that needs to be made. The
Insert picture description here
packaging is successful!
Insert picture description here
Select the project, click to run, you need to configure the corresponding file path

  1. How does uniapp perform routing jump

(1) Keep the current page, jump to a page in the app, use uni.navigateBack to return to the original page (if A->B frequently switches back and forth, do not
use this method for both methods A and B.) // Jump to the test.vue page on the start page and pass the parameter uni.navigateTo({ url:'test?id=1&name=uniapp' }); The page jump path has hierarchical restrictions, and you cannot jump to the new page without restrictions. You can only use switchTab to jump to the tabBar page

(2) Close the current page and jump to the path of the non-tabBar page in the application that needs to be jumped to a certain page in the application
. Parameters can be included after the path . The parameter and the path are separated by ?, the parameter key and the parameter value are connected by =, and the different parameters are separated by &; such
as'path?key=value&key2=value2' uni.redirectTo({ url:'test?key=value&key2=value2' });

(3) uni.reLaunch(OBJECT) Close all pages and open to a page in the app.

After calling uni.reLaunch on the H5 side, the previous page stack will be destroyed, but the previous history of the browser cannot be cleared. At this time, navigateBack cannot return.
If there is a history, click the browser's back button or call history.back() to still be able to navigate To the other history of the browser. Jump to the tabBar
page and close all other non-tabBar pages.

(4) uni.switchTab(OBJECT) Jump to the tabBar page and close all other non-tabBar pages.

(5) uni.navigateBack(OBJECT) Close the current page and return to the previous page or multi-level pages. You can
get the current page stack through getCurrentPages() and decide how many layers you need to return.

navigateTo, redirectTo can only open non-tabBar pages. switchTab can only open the tabBar page.
reLaunch can open any page. The tabBar at the bottom of the page is determined by the page, that is, as long as the page is defined as a tabBar, there is a tabBar at the bottom.
You cannot jump to the page in App.vue.
The page stack will disappear after the H5 page is refreshed. At this time, navigateBack cannot return. If you must return, you can use history.back() to navigate to other history records of the browser.

  1. How to configure tabbar

example:

// tabBar 配置
	"tabBar": {
		// 未选中字体颜色
	    "color": "#7A7E83",
	    // 选中字体颜色
	    "selectedColor": "red",
	    // 至少两个
	    "list": [{
	        // 点击跳转的路径
	        "pagePath": "pages/index/index",
	        // 未选中图片路径
	        "iconPath": "static/1.png",
	        // 选中的图片路径
	        "selectedIconPath": "static/11.png",
	        // 文本内容
	        "text": "首页"
	    }, {
	        "pagePath": "pages/class/class",
	        "iconPath": "static/2.png",
	        "selectedIconPath": "static/22.png",
	        "text": "分类"
	    }]
	},
  1. How to request an interface

Use the request provided by uni

uni.request({
    
    
			url: url,
			data: data,
			method: "GET",
			header,
			success(res) {
    
    
				resolve(res)
			},
			fail(res) {
    
    
				reject(res)
			})
		},
  1. What are the life cycles
  export default {
    
    
        	data() {
    
    
             	return {
    
    
                 title: 'Hello'
             }
         },
         	onLoad() {
    
    
             	console.log('页面加载')
         },
         	onShow() {
    
    
             	console.log('页面显示')
         },
         	onReady(){
    
    
             	console.log('页面初次显示')
         },
         	onHide() {
    
    
             	console.log('页面隐藏')
         },
         	onUnload() {
    
    
             	console.log('页面卸载')
         },
         	onBackPress(){
    
    
             	console.log('页面返回...')
         },
         	onShareAppMessage() {
    
    
             	console.log('点击分享')
         },
         	onReachBottom() {
    
    
             	console.log('下拉加载...')
         },
         	onPageScroll(){
    
    
             	console.log('页面滚动...')
         },
         	onPullDownRefresh() {
    
    
             	console.log('上拉刷新...')
             // uni.stopPullDownRefresh(); //停止下拉
         },
         	methods: {
    
    
            
         }
}
  1. What is nvue in uniapp? Describe his characteristics
> nvue开发与vue开发的常见区别 基于原生引擎的渲染,虽然还是前端技术栈,但和web开发肯定是有区别的。
> 
> nvue 页面控制显隐只可以使用v-if不可以使用v-show nvue
> 页面只能使用flex布局,不支持其他布局方式。页面开发前,首先想清楚这个页面的纵向内容有什么,哪些是要滚动的,然后每个纵向内容的横轴排布有什么,按
> flex 布局设计好界面。 nvue 页面的布局排列方向默认为竖排(column),如需改变布局方向,可以在 manifest.json
> app-plus -> nvue -> flex-direction 节点下修改,仅在 uni-app 模式下生效。详情。 nvue页面编译为H5、小程序时,会做一件css默认值对齐的工作。因为weex渲染引擎只支持flex,并且默认flex方向是垂直。而H5和小程序端,使用web渲染,默认不是flex,并且设置display:flex后,它的flex方向默认是水平而不是垂直的。所以nvue编译为H5、小程序时,会自动把页面默认布局设为flex、方向为垂直。当然开发者手动设置后会覆盖默认设置。
> 文字内容,必须、只能在<text>组件下。不能在<div><view>的text区域里直接写文字。否则即使渲染了,也无法绑定js里的变量。
> 只有text标签可以设置字体大小,字体颜色。 布局不能使用百分比、没有媒体查询。 nvue 切换横竖屏时可能导致样式出现问题,建议有
> nvue 的页面锁定手机方向。 支持的css有限,不过并不影响布局出你需要的界面,flex还是非常强大的。详见
> 不支持背景图。但可以使用image组件和层级来实现类似web中的背景效果。因为原生开发本身也没有web这种背景图概念
> css选择器支持的比较少,只能使用 class 选择器。详见 nvue
> 的各组件在安卓端默认是透明的,如果不设置background-color,可能会导致出现重影的问题。 class 进行绑定时只支持数组语法。
> Android端在一个页面内使用大量圆角边框会造成性能问题,尤其是多个角的样式还不一样的话更耗费性能。应避免这类使用。
> nvue页面没有bounce回弹效果,只有几个列表组件有bounce效果,包括 list、recycle-list、waterfall。
> 原生开发没有页面滚动的概念,页面内容高过屏幕高度并不会自动滚动,只有部分组件可滚动(list、waterfall、scroll-view/scroller),要滚得内容需要套在可滚动组件下。这不符合前端开发的习惯,所以在
> nvue 编译为 uni-app模式时,给页面外层自动套了一个
> scroller,页面内容过高会自动滚动。(组件不会套,页面有recycle-list时也不会套)。后续会提供配置,可以设置不自动套。 在
> App.vue 中定义的全局js变量不会在 nvue 页面生效。globalData和vuex是生效的。 App.vue
> 中定义的全局css,对nvue和vue页面同时生效。如果全局css中有些css在nvue下不支持,编译时控制台会报警,建议把这些不支持的css包裹在条件编译里,APP-PLUS-NVUE
> 不能在 style 中引入字体文件,nvue 中字体图标的使用参考:加载自定义字体。如果是本地字体,可以用plus.io的API转换路径。
> 目前不支持在 nvue 页面使用 typescript/ts。 nvue
> 页面关闭原生导航栏时,想要模拟状态栏,可以参考文章。但是,仍然强烈建议在nvue页面使用原生导航栏。nvue的渲染速度再快,也没有原生导航栏快。原生排版引擎解析json绘制原生导航栏耗时很少,而解析nvue的js绘制整个页面的耗时要大的多,尤其在新页面进入动画期间,对于复杂页面,没有原生导航栏会在动画期间产生整个屏幕的白屏或闪屏。

See https://uniapp.dcloud.io/use-weex for details

  1. How to store data, get data

Vuex can store global variables locally

  1. What is the most suitable css pixel unit to use

upx, rpx, vw, vh, etc.

  1. What are the problems on the project and how to solve them

Authorized login
configuration: (WeChat applet)
Insert picture description here
Insert picture description here
get wx code

uni.login({
    
    
		provider:"weixin",
		success:(res)=>{
    
    
		console.log("code:",res.code);
	},
})

to sum up

uni app can be regarded as a small program that uses veu syntax. The basic writing method is roughly the same as that of small programs, but the api and other wx we use need to be replaced with uni. If you need actual development, try to refer to official documents as much as possible

Guess you like

Origin blog.csdn.net/t5_5_5_5_5_7_7/article/details/110635933