你还不会用零基础的uniapp吗——uniapp快速搭建与跳转

效果
文章列表
在这里插入图片描述
文章详情
在这里插入图片描述

第一步:创建项目

打开hbuilderX:文件→新建→项目
选择uni-app → 默认模板 → 创建

在这里插入图片描述
运行项目到浏览器

在这里插入图片描述
在这里插入图片描述

第二步:简单实战,了解uni-app页面的搭建和跳转

我们需要用到uni-app官方提供的组件,可以从官网下载Hello uni-app

也可以使用HbuilderX创建项目选择Hello uni-app模板
在这里插入图片描述
在这里插入图片描述
创建完Hello uni-app组件模板后把common文件拷到我们自己的项目目录下使用
在这里插入图片描述
在app.vue中引入uni.css组件样式文件

<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>
 
<style>
	/*每个页面公共css */
	@import './common/uni.css';
</style>

两个主要页面
在这里插入图片描述

在pages中创建index文件页面index.vue
使用ulistmedia快捷代码片段

<template>
	<view class="content">
		<view class="uni-list">
			<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(item,index) in list" :key="index" @tap="goInfos(item)">
				<view class="uni-media-list">
					<image class="uni-media-list-logo" :src="item.cover"></image>
					<view class="uni-media-list-body">
						<view class="uni-media-list-text-top">{{item.title}}</view>
						<view class="uni-media-list-text-bottom uni-ellipsis">{{item.author_name}} {{item.created_at}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
 
<script>
	export default {
		data() {
			return {
				list: []
			}
		},
		onLoad() {
			var that = this
			uni.request({
				url: 'https://unidemo.dcloud.net.cn/api/news',
				method: 'GET',
				data: {},
				success: res => {
					// console.log("123",res.data)
					that.list = res.data
				},
				fail: () => {},
				complete: () => {}
			});
 
		},
		methods: {
			goInfos(oData){
				console.log(oData.post_id)
				uni.navigateTo({
					url: '../infos/infos?newid='+oData.post_id,
				});
			}
 
		}
	}
</script>
 
<style>
.uni-media-list-body{
	height: auto;
}
.uni-media-list-text-top{
	line-height: 1.6em;
}
</style>

跳转页面方法
在这里插入图片描述

文章详情page新建infos目录/infos.vue


{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
			"path": "pages/index/index",
			"style": {
				"navigationBarTitleText": "two-demo"
			}
		}
	    ,{
            "path" : "pages/infos/infos",
            "style" : {
				"navigationBarTitleText": "文章详情"
			}
        }
        ,{
            "path" : "pages/infos/infos",
            "style" : {}
        }
    ],
	"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "uni-app",
		"navigationBarBackgroundColor": "#F8F8F8",
		"backgroundColor": "#F8F8F8"
	}
}

page.json
注意下面文件的路径

  比如    "path" : "pages/infos/infos",

{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
			"path": "pages/index/index",
			"style": {
				"navigationBarTitleText": "two-demo"
			}
		}
	    ,{
            "path" : "pages/infos/infos",
            "style" : {
				"navigationBarTitleText": "文章详情"
			}
        }
        ,{
            "path" : "pages/infos/infos",
            "style" : {}
        }
    ],
	"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "uni-app",
		"navigationBarBackgroundColor": "#F8F8F8",
		"backgroundColor": "#F8F8F8"
	}
}

注意

在这里插入图片描述

运行到浏览器后
在这里插入图片描述

效果
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值