Vue部分
JS部分
笔记部分
a note
Vue部分
JS部分
笔记部分
在使用 vue2
+ axios
+ node.js
+ express
开发管理后台时,遇到了axios发送POST请求时后端获取不到参数的问题 ,查阅资料许久,还是未找到解决办法,无奈之下,喝一口凉水,歇息一番,继续寻求良方。
终于,皇天不负有心人,在这里,还是找到了解决的办法。
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
由此看出,axios
在 POST
提交数据时也是使用的这种方式,在 java
和 php
可以获取到对应的 request
原始流数据获取到对应的值并将其序列化.
但是这样的方式在 express
服务后端并不能获取到数据,因此 express
中使用的是 body-parser
去格式化前台传来的数据,具体实现看代码:
//server
'use strict'
var express = require('express')
var powerexpress = require('power-express')(express)
var authority = require('./filter/authority')
var app = powerexpress()
// 使用 body-parse 格式化数据
var bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({
extended: true
}))
app.use(bodyParser.json())
var Server = require('./server')
var cookieParser = require('cookie-parser')
app.use(cookieParser())
require('./controllers/routes')(app)
var appServer = new Server(app)
appServer.start()
在页面中进行web端直传,开发环境下测试没有问题,但部署到服务器上时出现了问题,服务器上的站点是基于https协议进行访问的,在此情况下,web端直传出现了异常,原因是在HTTPS的网页中,不允许发起HTTP的请求,可以使用https的endpoint,示例如下:
var client = new OSS.Wrapper({
region: 'oss-cn-shanghai',
secure: true, //为true时,即允许发起http请求
accessKeyId: '',
accessKeySecret: ''
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.