当前位置:网站首页>How to use wechat cloud hosting or cloud functions for cloud development of unapp development applet

How to use wechat cloud hosting or cloud functions for cloud development of unapp development applet

2022-07-07 06:23:00 Aasee.

One . Apply for wechat cloud hosting

Needless to say, it's necessary , Official address Here . Just go in and apply .
But the premise is that you have to be able to create docker file, Learn to master some basic docker knowledge , It will make it easier for you to create an environment . After the environment is created, the following operations can be carried out .

Two . So let's create one cloudfunctions Folder

 Insert picture description here
like this , Just put an empty file in it js ah css Anything will do , In this way, subsequent copies can be made .

Configuration path

Then we can go uniapp Inside manifest.json File configuration cloudfunctions The location of the folder , Take me as an example

"cloudfunctionRoot": "cloudfunctions/"

 Insert picture description here
because uniapp This file will not be compiled to mp-weixin platform , So here we copy it . Here I also refer to The code for this article . Download a plug-in first .

npm install -save [email protected]

After the download is complete, go to vue.config.js The file is configured as follows

const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')

module.exports = {
    
    configureWebpack: {
    
        plugins: [
            new CopyWebpackPlugin([
                {
    
                    from: path.join(__dirname, 'cloudfunctions'),
                    to: path.join(__dirname, 'try-music/dist', process.env.NODE_ENV === 'development' ? 'dev' : 'build', process.env.UNI_PLATFORM, 'cloudfunctions')
                }
            ])
        ]
    }
}

find uniapp The files created in are compiled into packages in the corresponding environment .
You should know the path .
 Insert picture description here
Just write down your own path .

3、 ... and . initialization , Then you can call .

One . initialization

stay App.vue In the document onLounch Add
 Insert picture description here
This is directly in Official wechat documents You can also see .

Two . Calling method

 Insert picture description here
Here you can go directly to uniapp Wechat cloud hosting service is used in , Of course, if you really feel troublesome, you can also use the opening directly https Server for use , You can also use uniapp Officially recommended unicloud service .

原网站

版权声明
本文为[Aasee.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070143148393.html