search

Home  >  Q&A  >  body text

laravel - vue-resourse has been imported, but the front end still reports an error!

The import method is as follows: import 'vue-resource'
Component usage post:
<script>

export default{
    data () {
        return {
            formSendCodeField:{
                phone: '',
                code: ''
            }
        }
    },
    methods: {
        sendCode () {
            this.$http.post('/api/phone/code', {phone: this.phone})
                .then(function (response) {
                    console.log(response);
                }, function(error){
                    console.log(error)
                })
        }
    }
}

</script>

The error message is: cannot read property "post" of ubdefined

黄舟黄舟2792 days ago455

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-05-16 16:51:20

    Are you using webpack? This is how you use webpack

    import  vueResource from 'vue-resource'
    Vue.use(VueResource);

    reply
    0
  • Cancelreply