uni-app Helloword

uni-app 创建项目

文件 -》 新建 -》 项目

helloword_new_project.png

创建完成后,找到pages/index/index.vue

<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello'
			}
		},
		onLoad() {

		},
		methods: {

		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>

从上面我们可以看到它有三大部分组成

  • template
  • scirpt
  • style

<template> 主要是写html代码,上面的view 类似html div, image 类似 html 的img 换句话说,它其实就是名字不一样,功能都差不多!

<style> 是写样式的地方,它也可以引入外部样式,这里不在做介绍;

在这个章节里,我们主要讲

data节点表示定义数据变量的地方,它在template 可直接使用,且不加this, 我们可以看到这个data节点我们定义了一个title变量,并赋值为 Hello, 在template 通过 {{title}} 获取;

onLoad 它是页面的一个生命周期, 主要是监听页面加载,其参数为上个页面传递的数据,参数类型为Object