Vue问题记录

1.[Vue warn]: Error in mounted hook:

在vue文件中的mounted方法中使用了this.items,但是在data() return 中没有写返回items,在data()中return中加入  items: [] 就没问题了


2.传boolean值给控件

    <component  :isBack=false></component>


3.图片路径问题

在同一个.vue文件中,在style中,路径是在这个vue相对img的路径的,在script中,图片路径是相对index.html


4.XMLHttpRequest cannot load http://localhost:3000/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 500.

 之前get的时候是没有问题的,之后发现是post未接收到数据,导致请求出错。

请求的时候,使用queryString()

import axios from "axios"
var qs = require('qs');
  axios.post(global.API + path, qs.stringify({
                username: username,
                password: pwd
            }), {
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                }
            }).then((res) => {
                let {
                    data,
                    code
                } = res.data;

                if (code == 200) {
                //.......
                } else {
                //.......
                }
            }, (res) => {
                console.log(res.status);
            });


后台处理请求

var bodyParser=require('body-parser');

var app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.post("/login", (req, res) => {
    let name = req.body.username;
    let pwd = req.body.password;
    //.........
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值