Shon Levi
Shon Levi

Reputation: 148

Using vue-cli, components throw "Uncaught ReferenceError: Vue is not defined"

I installed vue-cli and made some components, and everything was working great until I had to update some object values with keys

obj = {
    key1: value1,
    key2: value2,
    key3: value3
};

The data is updating, but the view isn't updating and when I dig into Vue documentation it says

Due to limitations in JavaScript, Vue cannot detect the following changes to an array:

  1. When you directly set an item with the index, e.g. vm.items[indexOfItem] = newValue

The solution would be to use Vue.set() but when try that (inside my component) I get the following result:

Vue.set(example1.items, indexOfItem, newValue);

Uncaught ReferenceError: Vue is not defined

Upvotes: 1

Views: 4162

Answers (2)

AlloyTeamZy
AlloyTeamZy

Reputation: 159

You forget the most important thing to introduce vue. The simplest, we can directly in the html file in the script tag to introduce vue, such as:

<script src="https://cdn.bootcss.com/vue/2.3.3/vue.min.js" type="text/javascript" charset="utf-8"></script>

In projects that use vue, individuals do not recommend configuring webpack and vue-loader separately. You can directly use vue official scaffolding, vue-cli. Do not have to consider these configurations, automatically configured.

vue-cli

If you just started learning Vue, here's an entry-level demo. Although it is only a small application, but it covers a lot of knowledge points (vue2.0 + vue-cli + vue-router + vuex + axios + mysql + express + pm2 + webpack), including front-end, back-end, database and other sites Some of the necessary elements, for me, learning great significance, would like to encourage each other!

Vue Demo

Upvotes: 0

Lo&#239;c Monard
Lo&#239;c Monard

Reputation: 690

You probably forgot to import your Vue in the component you're in

import Vue from 'vue'; 

This should solve

Upvotes: 6

Related Questions