Vue问题记录

来源:互联网 发布:windows一键还原软件 编辑:程序博客网 时间:2024/06/05 06:34

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
原创粉丝点击