Upload pictures on ElementUI+Express

in the development of the ElementUI+Express project, uploading pictures encountered this problem:

1ElementUI:
<el-upload action="http://localhost/goods/addNewGoodsPicture" :limit="1" :onError="uploadError" :onSuccess="uploadSuccess" list-type="picture">
    <el-button size="small" type="primary"></el-button>
</el-upload>



2:
router.post("/addNewGoodsPicture", function (req, res, next) {
  let newGoodsPicture = req.body.picture;
  console.log("newGoodsPicture"+newGoodsPicture);
  console.log("req:"+req);
})


3:
OPTIONS http://localhost/goods/addNewGoodsPicture net::ERR_CONNECTION_REFUSED

ElementUI+ExpressSF

confirm that the interface is available. Does the interface allow cross-domain access?


this one of yours is developed separately from the front and rear ends. There are cross-domains. You cors, Baidu and then express it

.
var cors = require('cors') ;
app.use(cors())
ok
Access-Control-Allow-Origin:*

is your backend service running on port 80? if not, add a port

the error is that the options request has been rejected. Generally speaking, the reason why the port you requested is not running is that the corresponding service is not running.

if you upload, you can use the multiparty package of the front-end formData+Node to do this requirement

Menu