Tag:node.jsjavascript
Article From:https://segmentfault.com/q/1010000012151126
Question:

webpack.dev.conf.jsFile — dev-server object

devServer: {
    clientLogLevel: 'warning',
    historyApiFallback: true,
    hot: true,
    host: process.env.HOST || config.dev.host,
    port: process.env.PORT || config.dev.port,
    open: config.dev.autoOpenBrowser,
    overlay: config.dev.errorOverlay ? {
      warnings: false,
      errors: true,
    } : false,
    publicPath: config.dev.assetsPublicPath,
    proxy: config.dev.proxyTable,
    quiet: true, // necessary for FriendlyErrorsPlugin
    watchOptions: {
      poll: config.dev.poll,
    },
    before(app) {
      app.get('/api/joke', function(req, res) {
        // The API address of the requestConst url ='http://api.jisuapi.com/xiaohua/text'Axios.get (URL, {Params: req.query}).Then ((response) => {Res.json (response)}).CaTCH ((error) => {Console.error (error)})})}}

joke.vuefile

created() {
    this.axios.get('/api/joke', {
        params: {
            appkey: 'appkey',
            pagenum: 1,
            pagesize: 20,
            sort: 'addtime'
        }
    }).then((res) => {
        console.log(res)
    }).catch((err) => {
        console.error(err)
    })
}

When running NPM run dev, report the following error

Params is no problem, because using proxyTable proxy can return data.
How can I solve this problem?

Answer 0:

A mistake step by step.
The wrong information is circulatory reference when serializing JSON. Where is JSON serialization used?
The whole file is oneres.json
So why is response a circular reference
Because Axios calls in the nodejs environment, it uses the HTTP module of nodejs instead of Ajax request.,The default response returned by the HTTP module is a very complex object that will be recycled to itself, similar to the window.window in the browser.

As long as it is changed tores.json(response.data)That’s OK.

Answer 1:

I want to ask how do you configure the express and Axios introduced before devServer? Now I have some problems.

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *