vue 音乐App QQ音乐搜索列表最新接口跨域设置

在 webpack.dev.config.js中

'use strict'= require('./utils'= require('webpack'= require('../config'= require('webpack-merge'= require('path'= require('./webpack.base.conf'= require('copy-webpack-plugin'= require('html-webpack-plugin'= require('friendly-errors-webpack-plugin'= require('portfinder' const express = require('express'= require('axios'= apiRoutes ='/api' == process.env.PORT &&const devWebpackConfig =<span style="color: #000000"> merge(baseWebpackConfig,{
module: {
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap,usePostCSS:
<span style="color: #0000ff">true
<span style="color: #000000"> })
},
<span style="color: #008000">//
<span style="color: #008000"> cheap-module-eval-source-map is faster for development

<span style="color: #000000"> devtool: config.dev.devtool,
<span style="color: #008000">//
<span style="color: #008000"> these devServer options should be customized in /config/index.js

<span style="color: #000000"> devServer: {
clientLogLevel:
'warning'<span style="color: #000000">,historyApiFallback: {
rewrites: [
{ from:
/.*/,to: path.posix.join(config.dev.assetsPublicPath,'index.html'<span style="color: #000000">) },],},
<span style="color: #008000">//
<span style="color: #008000">----------------axios 结合 node.js 代理后端请求

<span style="color: #000000"> before(app) {
<span style="color: #008000">//
<span style="color: #008000"> 推荐热门歌单

app.get('/api/getDiscList',<span style="color: #0000ff">function
<span style="color: #000000">(req,res) {
<span style="color: #0000ff">var
url = 'https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg'<span style="color: #000000">
axios.get(url,{
headers: {
referer:
'https://c.y.qq.com/'<span style="color: #000000">,host:
'c.y.qq.com'<span style="color: #000000">
},params: req.query
}).then((response)
=><span style="color: #000000"> {
res.json(response.data)
}).
<span style="color: #0000ff">catch((e) =><span style="color: #000000"> {
console.log(e)
})
}),<span style="color: #008000">//<span style="color: #008000"> 歌词
app.get('/api/getLyric',res) {
<span style="color: #0000ff">var url = 'https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg'<span style="color: #000000">

            axios.get(url,params: req.query
                })
                .then((response) </span>=><span style="color: #000000"&gt; {
                    </span><span style="color: #008000"&gt;//</span><span style="color: #008000"&gt; jsonp 数据转为 json 数据</span>
                    <span style="color: #0000ff"&gt;var</span> result =<span style="color: #000000"&gt; response.data
                    </span><span style="color: #0000ff"&gt;if</span> (<span style="color: #0000ff"&gt;typeof</span> result === 'string'<span style="color: #000000"&gt;) {
                        </span><span style="color: #0000ff"&gt;var</span> reg = /^\w+\(({[^()]+})\)$/
                        <span style="color: #0000ff"&gt;var</span> matches =<span style="color: #000000"&gt; result.match(reg)

                        </span><span style="color: #0000ff"&gt;if</span><span style="color: #000000"&gt; (matches) {
                            result </span>= JSON.parse(matches[1<span style="color: #000000"&gt;])
                        }
                    }
                    res.json(result)
                    </span><span style="color: #008000"&gt;//</span><span style="color: #008000"&gt; res.json(response.data)</span>

<span style="color: #000000"> })
.<span style="color: #0000ff">catch((error) =><span style="color: #000000"> {
console.log(error)
})
}),<span style="color: #008000">//<span style="color: #008000">搜索列表接口
<span style="color: #008000">//<span style="color: #008000"> https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp
app.get('/api/search',res) {
<span style="color: #0000ff">var url = 'https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp'<span style="color: #000000">
axios.get(url,params: req.query
}).then((response) =><span style="color: #000000"> {
res.json(response.data)
}).<span style="color: #0000ff">catch((e) =><span style="color: #000000"> {
console.log(e)
})
})
},<span style="color: #008000">//<span style="color: #008000">----------------axios 结合 node.js 代理后端请求
hot: <span style="color: #0000ff">true<span style="color: #000000">,contentBase: <span style="color: #0000ff">false,<span style="color: #008000">//<span style="color: #008000"> since we use CopyWebpackPlugin.
compress: <span style="color: #0000ff">true<span style="color: #000000">,host: HOST ||<span style="color: #000000"> config.dev.host,port: PORT ||<span style="color: #000000"> config.dev.port,open: config.dev.autoOpenBrowser,overlay: config.dev.errorOverlay ? { warnings: <span style="color: #0000ff">false,errors: <span style="color: #0000ff">true } : <span style="color: #0000ff">false<span style="color: #000000">,publicPath: config.dev.assetsPublicPath,proxy: config.dev.proxyTable,quiet: <span style="color: #0000ff">true,<span style="color: #008000">//<span style="color: #008000"> necessary for FriendlyErrorsPlugin
<span style="color: #000000"> watchOptions: {
poll: config.dev.poll,}
},plugins: [
<span style="color: #0000ff">new<span style="color: #000000"> webpack.DefinePlugin({
'process.env': require('../config/dev.env'<span style="color: #000000">)
}),<span style="color: #0000ff">new<span style="color: #000000"> webpack.HotModuleReplacementPlugin(),<span style="color: #0000ff">new webpack.NamedModulesPlugin(),<span style="color: #008000">//<span style="color: #008000"> HMR shows correct file names in console on update.
<span style="color: #0000ff">new<span style="color: #000000"> webpack.NoEmitOnErrorsPlugin(),<span style="color: #008000">//<span style="color: #008000"> https://github.com/ampedandwired/html-webpack-plugin
<span style="color: #0000ff">new<span style="color: #000000"> HtmlWebpackPlugin({
filename: 'index.html'<span style="color: #000000">,template: 'index.html'<span style="color: #000000">,inject: <span style="color: #0000ff">true<span style="color: #000000">
}),<span style="color: #008000">//<span style="color: #008000"> copy custom static assets
<span style="color: #0000ff">new<span style="color: #000000"> CopyWebpackPlugin([{
from: path.resolve(__dirname,'../static'<span style="color: #000000">),to: config.dev.assetsSubDirectory,ignore: ['.*'<span style="color: #000000">]
}])
]
})

module.exports = <span style="color: #0000ff">new Promise((resolve,reject) =><span style="color: #000000"> {
portfinder.basePort = process.env.PORT ||<span style="color: #000000"> config.dev.port
portfinder.getPort((err,port) =><span style="color: #000000"> {
<span style="color: #0000ff">if<span style="color: #000000"> (err) {
reject(err)
} <span style="color: #0000ff">else<span style="color: #000000"> {
<span style="color: #008000">//<span style="color: #008000"> publish the new Port,necessary for e2e tests
process.env.PORT =<span style="color: #000000"> port
<span style="color: #008000">//<span style="color: #008000"> add port to devServer config
devWebpackConfig.devServer.port =<span style="color: #000000"> port

        </span><span style="color: #008000"&gt;//</span><span style="color: #008000"&gt; Add FriendlyErrorsPlugin</span>
        devWebpackConfig.plugins.push(<span style="color: #0000ff"&gt;new</span><span style="color: #000000"&gt; FriendlyErrorsPlugin({
            compilationSuccessInfo: {
                messages: [`Your application is running here: http:</span><span style="color: #008000"&gt;//</span><span style="color: #008000"&gt;${devWebpackConfig.devServer.host}:${port}`],</span>

<span style="color: #000000"> },onErrors: config.dev.notifyOnErrors ?<span style="color: #000000"> utils.createNotifierCallback() : undefined
}))

        resolve(devWebpackConfig)
    }
})

})

在请求金封装的接口中

= '/api/search' = g_tk:53810'json''utf-8''utf-8'0'h5'11? 1 : 001'utf-8'1020'txt.mqq.all'1537612841753<span style="color: #0000ff">return<span style="color: #000000"> axios.get(url,{
params: data
}).then((res)
=><span style="color: #000000"> {
<span style="color: #008000">//
<span style="color: #008000">成功后返回

<span style="color: #0000ff">return
<span style="color: #000000"> Promise.resolve(res.data)
})
}

相关文章

https://segmentfault.com/a/1190000022018995 https://www....
ES6 (ECMAScript 6)中的模块是一个包含 JavaScript 代码的...
from https://mp.weixin.qq.com/s/-rc1lYYlsfx-wR4mQmIIQQ V...
D:\Temp&gt;npm init vite@latest vue3study --temp...
文章浏览阅读1.2k次。最近自己从零撸起的甘特图组件需要子组...
文章浏览阅读3.3k次,点赞3次,收藏16次。静默打印是什么?简...