感谢您阅读我的问题。
我已阅读有关我的问题
VUE JS 2 + WEBPACK Cannot read property 'get' of undefined VUE RESOURCE
但我的系统没有读过Vue var:(
我有一个vue组件调用app.vue,我需要使用vue-resource从我的帖子中获取数据。但错误很多次是:
TypeError: Cannot read property 'post' of undefined
at VueComponent.loadingProcess
你有想法解决它吗?
我的app.vue
<script>
var Vue = require('vue');
//Vue.use(require('vue-resource'));
//Vue.use();
export default {
data () {
return {
msg: 'Hello from vue-loader! nice!',
user: {}
}
},
mounted: function () {
this.loadingProcess();
},
methods: {
loadingProcess: function () {
var urlPost;
var answQSend = {...};
var that = this;
var jsonSend = {
"form_data": answQSend,
"prod_id": 3
};
Vue.$http.post(urlPost, jsonSend, {
"headers": {
"content-type": "application/json"
}
})
.then(function(response) {
})
...
提前致谢!
答案 0 :(得分:10)
首先,感谢@Bert耐心帮助我找到解决方案
在我的main.js中,我改变了这一行
SELECT oNum AS orderNumber,
cBillState AS Province
FROM orders
WHERE oNum IN ( '1482775424-189',
‘1482776094-127’,
‘1477536593-991’,
‘1479730802-590’,
‘1479920877-558’,
‘1479096422-217’,
‘1474903184-228’,
‘1477957959-648’,
‘1479275004-578’,
‘1480541117-247’,
‘1477092301-713’,
‘1477312082-716’,
‘1477398916-226’,
‘1477403920-962’,
‘1477413634-609’,
‘1477930535-606’,
‘1477955076-686’,
‘1478135196-101’,
‘1478276590-532’,
‘1478844924-162’,
‘1479359912-609’,
‘1479622476-128’,
‘1479623938-210’,
‘1479906995-505’,
‘1480054418-376’,
‘1480111928-502’,
‘1480125336-888’,
‘1480301567-671’,
‘1480365466-580’,
‘1480894281-609’,
‘1480949109-398’,
‘1479601155-364’,
‘1474307070-332’,
‘1480087806-183’,
‘1482787698-750’,
‘1469897352-353’,
‘1473537581-471’,
‘1473687519-991’,
‘1475351809-812’,
‘1476142232-535’,
‘1478902709-989’,
‘1482417573-419’,
‘1477361844-758’,
‘1480100297-559’,
‘1480994046-164’,
‘1478300763-269’,
‘1480056585-606’,
‘1480074372-121’,
‘1480380512-849’,
‘1480405548-219’,
‘1480945372-748’,
‘1480959346-958’,
‘1480979054-867’,
‘1480980513-214’,
‘1481068320-986’,
‘1481076087-716’,
‘1481305524-603’,
‘1481480028-875’,
‘1481733768-915’,
‘1480087091-948’,
‘1480439466-561’,
‘1482763826-493’,
‘1482905975-834’,
‘1486316457-550’,
‘1480018760-249’,
‘1479928546-617’,
‘1483471273-517’,
‘1484169298-747’,
‘1484190999-915’,
‘1477317500-446’,
‘1477971665-384’,
‘1478569145-467’,
‘1481561486-205’,
‘1481689248-289’,
‘1481689989-374’,
‘1482282006-867’,
‘1482425612-195’,
‘1482676243-627’,
‘1483240226-156’,
‘1483460319-161’,
‘1483465666-256’,
‘1486316720-332’,
‘1478731802-207’,
‘1482277678-164’,
‘1483984301-786’,
‘1483992584-520’,
‘1484020909-291’,
‘1480727936-335’,
‘1486869590-934’,
‘1483982035-667’,
‘1484018163-438’,
‘1484150283-139’,
‘1487613741-802’,
‘1483970473-109’,
‘1483974079-586’,
‘1483975971-790’,
‘1483978751-271’,
‘1483979075-338’,
‘1483983445-537’,
‘1483986171-592’,
‘1483986950-713’,
‘1483988578-641’,
‘1484019809-263’,
‘1484151424-647’,
‘1484171587-685’,
‘1484346681-146’,
‘1484509930-508’,
‘1484527687-400’,
‘1484757246-834’,
‘1486260387-326’,
‘1485277917-300’,
‘1487089945-259’,
‘1487300427-391’,
‘1487698559-786’,
‘1484418776-342’,
‘1480321037-286’,
‘1484262618-505’,
‘1484284655-434’,
‘1484447124-365’,
‘1482762650-132’,
‘1482851934-153’,
‘1482867677-237’,
‘1482956401-918’,
‘1484240287-695’,
‘1484445267-706’,
‘1484561817-854’,
‘1485565268-372’,
‘1487424684-789’,
‘1487467448-150’,
‘1488060650-455’,
‘1488066992-331’,
‘1488149236-354’,
‘1484063475-593’,
‘1484157094-588’,
‘1484859843-314’,
‘1485545522-819’,
‘1486516436-973’,
‘1486964775-771’,
‘1483145436-669’,
‘1483391592-704’,
‘1483502985-747’,
‘1483983727-219’,
‘1484023314-852’,
‘1484081233-200’,
‘1484322973-466’,
‘1484342291-447’,
‘1484406059-583’,
‘1484411015-328’,
‘1484425064-479’,
‘1484452295-582’,
‘1484515700-540’,
‘1484627708-335’,
‘1484632746-862’,
‘1485052037-249’,
‘1485128964-286’,
‘1485190492-888’,
‘1485195733-900’,
‘1485202785-384’,
‘1485216462-233’,
‘1485222790-976’,
‘1485357911-246’,
‘1485459961-895’,
‘1485483263-818’,
‘1485542911-608’,
‘1485568582-415’,
‘1485630460-879’,
‘1481134322-151’,
‘1484703008-980’,
‘1485846056-687’,
‘1484025532-550’,
‘1484066421-733’,
‘1484077460-592’,
‘1484149227-959’,
‘1484162618-303’,
‘1484420681-353’,
‘1484665197-540’,
‘1484755505-933’,
‘1484848858-607’,
‘1485217578-110’,
‘1485316847-965’,
‘1485567177-164’,
‘1485635160-954’,
‘1485713147-552’,
‘1485727727-861’,
‘1485868390-528’,
‘1485978054-311’,
‘1485995204-154’,
‘1486050211-126’,
‘1486232357-429’,
‘1483563899-665’,
‘1484482619-909’,
‘1487036669-169’,
‘1487531819-670’,
‘1489680045-522’,
‘1487607030-673’,
‘1487792756-848’,
‘1489592492-867’,
‘1485976581-271’,
‘1489762699-587’,
‘1489823936-264’,
‘1486680384-909’,
‘1490636775-210’);
的
var VueResource = require('vue-resource');
并使用
import VueResource from "vue-resource"
然后,在我的app vue组件中,我改变了
Vue.use(VueResource);
有关
Vue.http.post
这样我们就修正了错误!
答案 1 :(得分:0)
您使用的是导出默认脚本,因此您的this关键字无权访问Vue实例原始模块,而是访问导入的对象组件。最有可能的情况是,对于require,vue-resource仅对原始模块可用,因此使用来自“vue-resource”的import VueResource,使用es6语法,vue-resource库将被提升为内部模块,之后在Vue实例旁边的浏览器上进行评估和缓存。在某些情况下,人们不使用箭头功能并超出范围。 另一种方法是使用Vue实例本身而不是导出默认对象。看看http://voidcanvas.com/import-vs-require/你可能会比我做得更多。