4

I'm trying to use an ajax request by vue-resource to fill my data in vuejs.

But when I require the vue-resource returns in console this message: Uncaught TypeError: Cannot redefine property: $url

The error occurs in code:

var Vue = require('vue');
Vue.use(require('vue-resource'));
2
  • Are you sure you are requiring vue resource just once? and also what other dependencies are you using? Commented Apr 4, 2016 at 15:18
  • Yes, with this 2 lines, occurs this error, I'm using vue 1.0.20 and vue-resource 0.7.0 Commented Apr 4, 2016 at 17:49

1 Answer 1

8

It happens because you are calling the vue-resource twice!

As I know you are using Laravel + Vue + Vue Resource + Vueify + Browserify (sorry guys, I don't have enough reputation to add a comment on his question so I asked him through other way) make sure your code is like that:

main.js

'use strict';

import Vue from 'vue';
import VueResource from 'vue-resource';
import TrainingsList from './components/trainings/List.vue';

Vue.use(VueResource);

new Vue({
  el: 'body',
});

As you are importing the VueResource through your main.js:

import VueResource from 'vue-resource';

BE SURE it's not on your gulpfile.js. The code bellow is your problem as you are importing Vuejs by Browserify and compiling through gulp

mix.scripts([
  '/../../../node_modules/vue/vue.js',
  '/../../../node_modules/vue-resource/vue-resource.js',
], 'public/js/scripts.js');

mix.browserify('main.js');

Everything you need to do is remove your vue and vue-resource from the gulpfile and your problem goes away!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.