微信小程序-JAVA Springboot项目-小程序搭建-项目搭建01

欢乐狗  论坛元老 | 2024-6-22 17:44:57 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 1020|帖子 1020|积分 3060

目次
一、序言
二、小程序搭建


一、序言

        本文主要报告一个微信小程序前后端项目搭建的过程,主要内容包括小程序(前端)搭建和后端搭建,此中会描述可能遇到的问题以及解决步伐,文章将会分为几个部门进行报告,这章将报告前端小程序搭建的内容,此中包括软件下载、客户端向服务端发送数据,吸取并处置处罚来自服务端的数据等内容;本项目的前端运用的框架是uni-app,后端运用的框架是Springboot,如各位需求满足,可继续往下看;
        关于前后端分离的利益,个人认为是可以增加代码可维护性,降低了很多后期维护本钱,更容易发现问题,解决问题;其次项目可以分工给团队,减少开辟难度。对于新手或者想要独立完成一个总体项目的同志是个不错的练习。
二、小程序搭建

1、开辟语言
        本项目运用的框架是uni-app,uni-app是一个使用 Vue.js 开辟所有前端应用的框架,该框架的开辟语言类似于vue.js,语法的规则有些变化(具体变化查看以下链接);
白话uni-app | uni-app官网 (dcloud.net.cn)
https://uniapp.dcloud.net.cn/vernacular.html#         vue建立在尺度 HTML、CSS 和 JavaScript 之上,以是涉及的开辟语言要了解:vue、CSS、JavaScript、HTML;如果是新手莫张皇,语法较简单,看一看例子就能简单上手,以下是uni-app官方的教程链接;
        常使用的主要三个语言板块:html、css、javascript,查看此中的一些格式变化即可。
uni-app构成和跨端原理 | uni-app官网 (dcloud.net.cn)
https://uniapp.dcloud.net.cn/tutorial/
2、开辟工具


  • HBuilderX(下载地址如下)
HBuilderX-高效极客本事 (dcloud.io)
https://www.dcloud.io/hbuilderx.html


  • 微信开辟者工具(下载地址如下)
微信开辟者工具下载地址与更新日志 | 微信开放文档 (qq.com)
https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html        下载稳固版本即可

3、平台注册或登录,获取小程序APPID
微信公众平台 (qq.com)
https://mp.weixin.qq.com/        小程序开辟必要APPID才能发布或发行,这个步骤必要进入平台,注册登录后,填写小程序信息,然后获取APPID即可;
4、创建uni-app项目(这部门属于项目的前端部门)

        选择uni-app项目,选择默认版本,vue选择版本2即可,如果选择vue3,那么根据官方教程学习即可;本项目选择的是vue2;
        创建后项目的目次如图所示:

5、编写项目
        这里编写一个小demo,实现前端接口向后端传输数据,以及吸取后端传来的数据;
         打开index页面,编写代码:
  1. <template>
  2.         <view class="content">
  3.                 <image class="logo" src="/static/logo.png"></image>
  4.                 <view class="text-area">
  5.                         <text class="title">名称:{{title}}</text>
  6.                 </view>
  7.                 <input class="input-box" placeholder="请输入修改的名称" @input="setTitle" />
  8.                 <button @click="postData"> 修改</button>
  9.         </view>
  10. </template>
  11. <script>
  12.         export default {
  13.                 data() {
  14.                         return {
  15.                                 title: 'Hello',
  16.                                 tempTitle: ""
  17.                         }
  18.                 },
  19.                 onLoad() {
  20.                         let isThis = this;
  21.                         var option = {
  22.                                 method: "GET",
  23.                         };
  24.                         isThis.getData(option);
  25.                 },
  26.                 methods: {
  27.                         setTitle: function(e) {
  28.                                 console.log(e.detail.value)
  29.                                 this.tempTitle = e.detail.value;
  30.                         },
  31.                         getData(option) {
  32.                                 let isThis = this;
  33.                                 uni.showLoading({
  34.                                         title: '加载中',
  35.                                         mask: false
  36.                                 });
  37.                                 uni.request({
  38.                                         url: '',
  39.                                         method: option.method || 'GET', //不传默认为GET
  40.                                         data: option.data || {}, //不传默认为空
  41.                                         header: option.header || {
  42.                                                 'Content-Type': 'application/json'
  43.                                         },
  44.                                         success: (res) => {
  45.                                                 if (res.data.status == 1) {
  46.                                                         isThis.title = res.data.data.title;
  47.                                                         uni.hideLoading();
  48.                                                 } else {
  49.                                                         isThis.title = "";
  50.                                                         uni.hideLoading();
  51.                                                         uni.showModal({
  52.                                                                 title: '提示',
  53.                                                                 content: res.data.msg,
  54.                                                                 showCancel: false,
  55.                                                                 success: res => {},
  56.                                                                 fail: () => {},
  57.                                                                 complete: () => {}
  58.                                                         });
  59.                                                 }
  60.                                         },
  61.                                         fail: (err) => {
  62.                                                 uni.showToast({
  63.                                                         icon: 'none',
  64.                                                         title: '啊哦~ 服务器出问题了,请刷新!',
  65.                                                         duration: 2000
  66.                                                 });
  67.                                         }
  68.                                 })
  69.                         },
  70.                         postData() {
  71.                                 let isThis = this;
  72.                                 uni.showLoading({
  73.                                         title: '加载中',
  74.                                         mask: false
  75.                                 });
  76.                                 var data = {
  77.                                         "title": isThis.tempTitle,
  78.                                 }
  79.                                 uni.request({
  80.                                         url: '',
  81.                                         method: 'POST',
  82.                                         data: data,
  83.                                         header: {
  84.                                                 'Content-Type': 'application/json'
  85.                                         },
  86.                                         success: (res) => {
  87.                                                 if (res.data.status == 1) {
  88.                                                         uni.hideLoading();
  89.                                                 } else {
  90.                                                         uni.hideLoading();
  91.                                                         uni.showModal({
  92.                                                                 title: '提示',
  93.                                                                 content: res.data.msg,
  94.                                                                 showCancel: false,
  95.                                                                 success: res => {},
  96.                                                                 fail: () => {},
  97.                                                                 complete: () => {}
  98.                                                         });
  99.                                                 }
  100.                                         },
  101.                                         fail: (err) => {
  102.                                                 uni.showToast({
  103.                                                         icon: 'none',
  104.                                                         title: '啊哦~ 服务器出问题了,请刷新!',
  105.                                                         duration: 2000
  106.                                                 });
  107.                                         }
  108.                                 })
  109.                         },
  110.                 }
  111.         }
  112. </script>
  113. <style>
  114.         .content {
  115.                 display: flex;
  116.                 flex-direction: column;
  117.                 align-items: center;
  118.                 justify-content: center;
  119.         }
  120.         .logo {
  121.                 height: 200rpx;
  122.                 width: 200rpx;
  123.                 margin-top: 200rpx;
  124.                 margin-left: auto;
  125.                 margin-right: auto;
  126.                 margin-bottom: 50rpx;
  127.         }
  128.         .text-area {
  129.                 display: flex;
  130.                 justify-content: center;
  131.         }
  132.         .title {
  133.                 font-size: 36rpx;
  134.                 color: #8f8f94;
  135.         }
  136.         .input-box {
  137.                 margin: 10px auto;
  138.                 padding: 10px;
  139.                 width: 80%;
  140.                 border: #b8b8be 1px solid;
  141.                 height: 60rpx;
  142.                 border-radius: 10px;
  143.         }
  144. </style>
复制代码
(1)前端吸取后端数据
   getData(option) {
                let isThis = this;
                uni.showLoading({
                    title: '加载中',
                    mask: false
                });
                uni.request({
                    url: '',  //后端接口
                    method: option.method || 'GET', //不传默认为GET
                    data: option.data || {}, //不传默认为空
                    header: option.header || {
                        'Content-Type': 'application/json'
                    }, 
                    success: (res) => {
                        if (res.data.status == 1) {
                            isThis.title = res.data.data.title;
                            uni.hideLoading();
                        } else {
                            isThis.title = "";
                            uni.hideLoading();
                            uni.showModal({
                                title: '提示',
                                content: res.data.msg,
                                showCancel: false,
                                success: res => {},
                                fail: () => {},
                                complete: () => {}
                            });
                        }
                    },
                    fail: (err) => {
                        uni.showToast({
                            icon: 'none',
                            title: '啊哦~ 服务器出问题了,请刷新!',
                            duration: 2000
                        });
                    }
                })
            },
  (2)前端发送数据
   postData() {
                let isThis = this;
                uni.showLoading({
                    title: '加载中',
                    mask: false
                });
                var data = {
                    "title": isThis.tempTitle,
                }
                uni.request({
                    url: '',    //后端接口
                    method: 'POST',
                    data: data,
                    header: {
                        'Content-Type': 'application/json'
                    },
                    success: (res) => {
                        if (res.data.status == 1) {
                            uni.hideLoading();
                        } else {
                            uni.hideLoading();
                            uni.showModal({
                                title: '提示',
                                content: res.data.msg,
                                showCancel: false,
                                success: res => {},
                                fail: () => {},
                                complete: () => {}
                            });
                        }
                    },
                    fail: (err) => {
                        uni.showToast({
                            icon: 'none',
                            title: '啊哦~ 服务器出问题了,请刷新!',
                            duration: 2000
                        });
                    }
                })
            },
  6、填写获取的APPID
        找到项目的根目次的manifest.json文件,选择“微信小程序配置”,填写对应的APPID;

7、配置小程序模拟器
        点击菜单栏“运行”,选择“运行到小程序模拟器”,选择“运行设置”,设置微信开辟者工具路径


8、运行项目
    运行小程序模拟器查看项目效果,且修改代码可以实时显现修改效果
        

        如果没有下载微信开辟者工具,那么可以选择运行到欣赏器进行查看项目效果,然后选择对应的欣赏器即可;

微信开辟者工具效果图:

        可能出现运行不乐成的问题,解决步伐如下

        到此前端搭建根本完成,接下来进军后端部门!

请查看下一章内容 ❤微信小程序-JAVA Springboot项目-后端搭建-项目搭建02-CSDN博客
https://blog.csdn.net/qq_53316719/article/details/133924718?spm=1001.2014.3001.5501


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

欢乐狗

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表