1
0
积极分子
一、实战
- 返回数据格式 - id 新闻id 如: 72980 - title 标题 - created_at 创建时间 - author_avatar 图标
https://unidemo.dcloud.net.cn/api/news/36kr/ + id ( id 为新闻id,上个页面传过来的)
<rich-text class="richText" :nodes="strings" ></rich-text>
onLoad: function() { 快捷写法 -> ureq }
请求列表数据:
onLoad:function(){ uni.request({ url: 'https://unidemo.dcloud.net.cn/api/news', method: 'GET', data: {}, success: res => { console.log(res) }, fail: () => {}, complete: () => {} }); }
// ① <navigator url=""></navigator> // ② @tap="openinfo" //监听单击事件 // 快捷写法 : me -> 选择 Vue methods方法代码块 // unav -> 选择 uni.navigateTo({ 代码块 }) methods: { openinfo() { uni.navigateTo({ url: '../info/info' }); } },
// index.vue 列表页 :data-newsid="item.post_id" methods: { openinfo(e) { var newsid = e.currentTarget.dataset.newsid; //console.log(newsid) uni.navigateTo({ url: '../info/info?newsid='+newsid }); } }, // info.vue 详情页 // onLoad生命周期:页面加载成功,获取传递的参数,保存在onLoad方法的 e.变量名称 中 onLoad: function(e){ console.log(e) //{newsid: "5219628" } }
uni.showLoading({ title: "加载中...." })
uni.hideLoading()
"pages": [ // pages数组中第一项表示应用启动页,参考: // https://uniapp.dcloud.io/collocation/pages { "path": "pages/index/index", "style": { "navigationBarTitleText": "uni-app" } } , //在使用HBuilderX新建info页面文件夹时,自动创建 { "path" : "pages/info/info", "style" : {} } ],
"condition": { //模式配置,仅开发期间生效 "current": 0, //当前激活的模式(list 的索引项) "list": [{ "name": "test", //模式名称 "path": "pages/info/info", //启动页面,必选 "query": "newsid=5158607" //启动参数,在页面的onLoad函数里可得到 }] }
二、白话uni-app —— html、vue、小程序的区别
https://uniapp.dcloud.io/api/media/background-audio-manager?id=getbackgroundaudiomanager
三、基于Promise封装uni-app的request方法,实现类似axios形式的请求
var Fly=require("flyio/dist/npm/wx"); var fly=new Fly; var server = "https://uniapp.dcloud.io/update"; var req = {"appid":"123","version":"123"}; fly.request(server, req, { method:"get", timeout:5000 //超时设置为5s }) .then( d=>{ console.log("request result:",d) }) .catch( (e) => console.log("error", e) );
注:以上内容来自UniApp官网推荐教程
使用道具 举报
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com
Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.