大家平时经常使用新闻类APP进行资讯浏览,但是怎样用代码实现一个新闻APP呢?常用的移动端开发一般分为两大类,一类是原生APP开发,比如谷歌的那一套技术,android studio作为开发工具,使用java或kotlin的语法。
另一类是第三方的框架,比如Flutter或者uni-app今天介绍的就是使用uni-app发开一个新闻手机软件uni-app 是一个使用 Vue.js 开发所有前端应用的框架,开发者编写一套代码,可发布到iOS、Android、Web(响应式)、以及各种小程序(微信/支付宝/百度/头条/飞书/QQ/快手/钉钉/淘宝)、快应用等多个平台。
实现的功能分为管理员和普通用户两种角色,普通用户可以自行注册账号,有图片验证码;普通用户:搜索、查看、点赞、收藏、评论头条新闻、查看评论回复和收藏等信息、与人工智能机器人聊天、修改个人信息等;管理员:除普通用户的功能以外,还包括评论管理、文章管理、分类管理等。
用到的技术后端是java语言的SpringBoot框架,MySql5.7或8数据库,Maven依赖管理;前端是Vue.js语法的UniApp框架。
部分代码展示
prefix-icon="cl-icon-search":placeholder="hotTitle">
@click="toMessage" />
justify="start"unColor="#999999"show-dropdown:border="false" @tab-change="activeTab" >
>
="toDetail(item)">
="32":ellipsis="2" >{{tName}}
{{ item.createTime }}
mode="" />
:visible.sync="visible"size="90%":padding="36"direction="center">
="item"v-for="(item, index) in publish":key="index" @tap="toPublish" >
{{ item.name }}
>import appRequest from"@/common/appRequestUrl.js"
; exportdefault { data() { return { user:"", hotTitle: "热搜:热搜内容标题", searchText:"", active
: "", tName:"最新", tabs: [ { label: "最新", name: "" } ], list: [ ], hotTime:
"15:09", open: require("@/static/icon/publish.png"), visible: false, publish: [ { icon:
require("@/static/icon/publish1.png"), name: "创建文章" } ], }; },onLoad() { },onShow() { this
.user = appRequest.getUserInfo(); this.getType(); this.getData(); }, methods: { activeTab(name){
var _this = this; this.tabs.map(function(item,index){ if(item.name == name){ _this.tName = item.label; } });
this.getData(name); }, getData(type){ var _this = this; appRequest.request({ method: "POST"
, url: appRequest.urlMap.findNmArticleList, data:{ validFlag:1, type:type, title
:this.searchText }, success: function(res) { if (res.data.code == 200) { let data = res.data.data; _this.list = data;
console.log(JSON.stringify(data)); }else{ uni.showToast({ title:"获取失败", icon
:"none" }) } }, fail: function(res) { uni.showToast({ title:"网络异常",
icon:"none" }) } }) }, getType(){ var _this = this; appRequest.request({ method
: "POST", url: appRequest.urlMap.findNmInfoTypeList, data:{ validFlag:1 }, success
: function(res) { if (res.data.code == 200) { let data = res.data.data; data.map(function
(item,index,arr){ _this.tabs.push({ label:item.typeName , name: item.tid }); }) }else
{ uni.showToast({ title:"获取失败", icon:"none" }) } }, fail: function
(res) { uni.showToast({ title:"网络异常", icon:"none" }) } }) },getPicUrl(info) {
if(info){ if( info.length > 10 ){ return info; }else { return appRequest.urlMap.getPicById + info; } }
else { return""; } }, toSearch() { uni.navigateTo({ url: "/pages/search/index", }); }, toDetail(item) { uni.navigateTo({
url: "/pages/news/detail?id="+item.id, }); }, onOpen() { this.visible = true; }, toPublish() {
this.visible = false; uni.navigateTo({ url: "/pages/publish/index", }); }, toMessage() { uni.navigateTo({
url: "/pages/message/index", }); }, }, }; 获取源码请关注后私信“20230523”
亲爱的读者们,感谢您花时间阅读本文。如果您对本文有任何疑问或建议,请随时联系我。我非常乐意与您交流。
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。