Vue js:无法重新定义 属性:$url

Vue js: cannot redefine property: $url

我正在尝试使用 vue-resource 的 ajax 请求在 vuejs 中填充我的数据。

但是当我在控制台中需要 vue-resource returns 时,这条消息: 未捕获类型错误:无法重新定义 属性:$url

代码中出现错误:

var Vue = require('vue');
Vue.use(require('vue-resource'));

发生这种情况是因为您调用了两次 vue-resource!

据我所知,您正在使用 Laravel + Vue + Vue Resource + Vueify + Browserify(抱歉,我没有足够的声誉来对他的问题发表评论,所以我通过其他方式问了他) 确保你的代码是这样的:

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',
});

当您通过 main.js 导入 VueResource 时:

import VueResource from 'vue-resource';

请确定它不在您的 gulpfile.js 上。下面的代码是您的问题,因为您正在通过 Browserify 导入 Vuejs 并通过 gulp

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

mix.browserify('main.js');

您需要做的就是从 gulp 文件中删除您的 vue 和 vue-resource,您的问题就会消失!