当前位置:   article > 正文

使用uni-app开发(h5、小程序、app)步骤_uniapp创建h5项目

uniapp创建h5项目

uni-app介绍

uni-app 是一个使用 Vue.js 开发所有前端应用的框架,开发者编写一套代码,可发布到iOS、Android、H5、以及各种小程序(微信/支付宝/百度/头条/QQ/钉钉)等多个平台。

官网地址(使用文档

https://uniapp.dcloud.io/README

这里创建小程序为例

开发工具:Hbuilder 、微信开发者工具

打开如下hbuilder首先创建一个项目,不是正真开发的项目 ,一会要用到里面的文件 ,当然这个可以作为其他组件使用参照

接着创建要开发的项目

复制第一次创建的项目中的common到这个oa项目中 ,

将common中的uni.css引入

将这个oa运行到微信小程序开发工具中

这里开发一个新闻列表页

index.vue代码

  1. <template>
  2. <view class="content">
  3. <view class="uni-list">
  4. <view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(item,index) in list" :key="index"
  5. @tap="openinfo" :data-id="item.id">
  6. <view class="uni-media-list">
  7. <image class="uni-media-list-logo" :src="item.author_avatar"></image>
  8. <view class="uni-media-list-body">
  9. <view class="uni-media-list-text-top">{{item.title}}</view>
  10. <view class="uni-media-list-text-bottom uni-ellipsis">{{item.content}}</view>
  11. </view>
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. list:[]
  22. }
  23. },
  24. /* 页面加载成功会执行 */
  25. onLoad() {
  26. uni.showLoading({
  27. title:'加载中...'
  28. })
  29. uni.request({
  30. url:'https://unidemo.dcloud.net.cn/api/news',
  31. method:'GET',
  32. data:{},
  33. success: res=>{
  34. this.list=res.data;
  35. uni.hideLoading()
  36. },
  37. complete: () => {
  38. },
  39. complete: () => {
  40. }
  41. })
  42. },
  43. methods: {
  44. openinfo(e){
  45. var id = e.currentTarget.dataset.id;
  46. console.log(id)
  47. uni.navigateTo({
  48. url: '../info/info?newid='+id,
  49. });
  50. }
  51. }
  52. }
  53. </script>
  54. <style>
  55. .content {
  56. display: flex;
  57. flex-direction: column;
  58. align-items: center;
  59. justify-content: center;
  60. }
  61. </style>

info.vue代码 

  1. <template>
  2. <view class="content">
  3. <rich-text class="richtext" :nodes="content"></rich-text>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. title: '',
  11. content: ''
  12. }
  13. },
  14. onLoad:function(e){
  15. console.log(e.newid)
  16. uni.request({
  17. url:'https://unidemo.dcloud.net.cn/api/news/36kr/'+e.newid,
  18. method:'GET',
  19. data:{},
  20. success: res => {
  21. console.log(res),
  22. this.title=res.data.title,
  23. this.content=res.data.content
  24. }
  25. })
  26. }
  27. }
  28. </script>
  29. <style>
  30. </style>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/273979
推荐阅读
相关标签
  

闽ICP备14008679号