javascript - Can't js be introduced into the vue project to control the class of elements?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-07-05 10:42:02
0
3
963

This is the situation of the console in the imported js

This is the case in elements

nav has not changed either.
How is this going?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(3)
仅有的幸福

I don’t see where the problem is. When asking questions, first clarify your thoughts and expose the problem points.

Answer questions

Can’t js be introduced into the vue project to control the class of elements?

It is possible to introduce tools such as jQuery to operate the dom

仅有的幸福

In fact, it is very convenient to deal with such problems in VueJS, here is an example.

View online https://jsfiddle.net/wqbtt12c/

The specific code is as follows:

<p id="app">
  <p :class="classStr" @click="changeClass">点我</p>
</p>
const classPool = ['red', 'blue', 'yellow'];

new Vue({
    el: '#app',
  data() {
      return {
        classStr: 'red'
    }
  },
  methods: {
      changeClass() {
        this.classStr = classPool[Math.ceil(Math.random()*3.0) - 1];
    }
  }
});
#app > p {
  width: 100px;
  height: 100px;
  line-height: 100px;
  text-align: center;
}
.red {
  background: red;
}

.blue {
  background: blue;
}

.yellow {
  background: yellow;
}
过去多啦不再A梦

In the vue project, the operation must be mounted after the element to be operated is mounted. I fainted.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template