Understanding of Vuex:

The biggest difference between Vuex of Vue3 and Vuex of Vue2 is the difference in instantiation:

In Vue2:

// instantiate Vue2
 new Vuex.Store({})
Copy the code

In Vue3:

// This is typical of Vue3: import on demand
In Vue3 it changed its name and is now called createStore
import { createStore } from 'vuex'
// instantiate Vue3
export default createStore({
  / / state
  state: {},// Change the status
  mutations: {},// Asynchronous operation
  actions: {},// Modular split
  modules: {},// Similar to component computed properties
  getters: {}})Copy the code

Create a store object using createStore instead of new


Option API and composition API understanding:

What is the Options API

  • This is the option API notation we used in the Vue2. X project

    • Code style: data options write data, methods options write functions… , a functional logic of code dispersion.
    • Advantages: Easy to learn and use, the location of the code has been agreed
    • Disadvantages: poor code organization, similar logic (function) code is not easy to reuse, logic complex code is not easy to read.

What is the Composition API: Composition API

  • Organizing your code by function makes it easier to reuse functionality later.

Bottom line: The biggest benefit of a composite API is that it organizes your code in terms of functionality, making it easier to reuse code