Som*_*mer 2 components webpack vue.js vue-resource
感谢您阅读我的问题.
我已经读过我的问题
VUE JS 2 + WEBPACK无法读取未定义的VUE RESOURCE属性'get'
但我的系统没有读取Vue var :(
我有一个vue组件调用app.vue,我需要使用vue-resource从我的帖子中获取数据.但错误很多次是:
TypeError: Cannot read property 'post' of undefined
at VueComponent.loadingProcess
Run Code Online (Sandbox Code Playgroud)
你有想法解决它吗?
我的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) {
})
...
Run Code Online (Sandbox Code Playgroud)
提前致谢!
Som*_*mer 10
首先,感谢@Bert耐心帮助我找到解决方案
在我的main.js中,我改变了这一行
var VueResource = require('vue-resource');
Run Code Online (Sandbox Code Playgroud)
对于
import VueResource from "vue-resource"
Run Code Online (Sandbox Code Playgroud)
并使用
Vue.use(VueResource);
Run Code Online (Sandbox Code Playgroud)
然后,在我的app vue组件中,我改变了
Vue.http.post
Run Code Online (Sandbox Code Playgroud)
对于
this.$http.post
Run Code Online (Sandbox Code Playgroud)
那样我们修正了错误!
| 归档时间: |
|
| 查看次数: |
8623 次 |
| 最近记录: |