0

下面代码报错了,求大神解答

Uncaught TypeError: Cannot read property 'post' of undefined
    at VueComponent.submit (eval at <anonymous> (app.js:860), <anonymous>:24:14)
    at Proxy.boundFn (eval at <anonymous> (app.js:765), <anonymous>:125:14)
    at submit (eval at <anonymous> (app.js:1148), <anonymous>:10:13)
<template>

    <div id="machine-header">
          <form @submit.prevent="submit">
            <div id="machine-list" class="field">
                <select>
                    <option v-for="machine_name in get_machine_list" ref="selectedMachine">
                        {{ machine_name }}
                    </option>
                </select>
            </div>
        
            <input type="submit" value="提交">
          </form>
    </div>

</template>

<script>
    export default {
        data() {
            return {
                machine_name: ''
            };
        },

        computed: {
               get_machine_list() {
                   return ['fd-11', 'fd-12', 'fd-13'];
               }
        },
        methods: {
            submit: function() {
                var formData = JSON.stringify(this.$refs.selectedMachine.value); 

                this.$http.post('/path/to', formData).then((response) => {
                      // success callback
                }, (response) => {
                      // error callback
                });
            }
        }

    }
</script>

2个回答

0

已采纳

var Vue = require('vue');

var VueResource = require('vue-resource');

Vue.use(VueResource);

0

不需要 vueresource的话你的$http哪里来的??
不行就用fetch或者原生xhr咯

撰写答案

SegmentFault

一起探索更多未知

下载 App