使用 vue.js 的 get⼀post请求错误 “ Cannot read property ✀get✀ of undefined”

代码 this.$http.get("data/address.json",{}).then(function (response) {});
2025-03-31 11:22:37
推荐回答(2个)
回答1:

你是不是没有引入vue-resource,或者引入的文件缺失了

回答2:

解决方法如下:

  • 完整的代码如下(遇到类型问题的同学可以做个参考):

  • 复制代码 代码如下:

  • var querystring = require('querystring')

, http = require('http');

var data = querystring.stringify({

info:'hi',

test:5

});

var opt = {

hostname:'www.test.com',

port :9094,

path:'/perationSqlQuery',

method: 'POST',

headers: {   

'Content-Type':'application/x-www-form-urlencoded',

'Content-Length': data.length  

};

var req = http.request(opt, function (res) {  

res.on('data', function (data) {

console.log(data.toString());

});

});

req.on('error', function(e) {

console.log('problem with request: ' + e.message);

});

req.write(data);

req.end();