B
B
beduin012019-01-29 16:52:24
Vue.js
beduin01, 2019-01-29 16:52:24

What should you use Vue.observable for?

I read an article about Vue.observable here.
The article has an example.

import Vue from vue;

const state = Vue.observable({
  counter: 0,
});

export default {
  render() {
    return (
      <div>
        {state.counter}

        <button v-on:click={() => { state.counter++; }}>
          Increment counter
        </button>
      </div>
    );
  },
};

I do not quite understand how the specified increment will differ from the variable increment placed in the `data` section.
Can the new feature be used as a replacement for the Vuex bus?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2019-01-29
@beduin01

Vue.observableallows you to create objects that are not tied to a specific component, changes in which will cause all dependent elements to be redrawn.
Roughly speaking, this is a lower level of abstraction. When you create an object in a section datasomewhere, internally Vue uses Vue.observable. It's just now that this feature has become available globally.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question