VueJS: Hot reloading

Các khóa học qua video:
Python SQL Server PHP C# Lập trình C Java HTML5-CSS3-JavaScript
Học trên YouTube <76K/tháng. Đăng ký Hội viên
Viết nhanh hơn - Học tốt hơn
Giải phóng thời gian, khai phóng năng lực

Vuex hỗ trợ hot-reloading các mutation, mô-đun, action và getters trong quá trình phát triển, sử dụng API thay thế mô-đun nóng của webpack. Bạn cũng có thể sử dụng nó trong Browserify với browserify-HMR plugin.

Đối với các mutation và mô-đun, bạn cần sử dụng phương thức API store.hotUpdate():

// store.js
import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import moduleA from './modules/a'

Vue.use(Vuex)

const state = { ... }

const store = new Vuex.Store({
  state,
  mutations,
  modules: {
    a: moduleA
  }
})

if (module.hot) {
  // accept actions and mutations as hot modules
  module.hot.accept(['./mutations', './modules/a'], () => {
    // require the updated modules
    // have to add .default here due to babel 6 module output
    const newMutations = require('./mutations').default
    const newModuleA = require('./modules/a').default
    // swap in the new modules and mutations
    store.hotUpdate({
      mutations: newMutations,
      modules: {
        a: newModuleA
      }
    })
  })
}

Kiểm tra ví dụ nóng phản hồi để phát lại bằng tải lại.

» Tiếp: Vue.js Hướng dẫn hiển thị phía máy chủ
« Trước: Thử nghiệm
Các khóa học qua video:
Python SQL Server PHP C# Lập trình C Java HTML5-CSS3-JavaScript
Học trên YouTube <76K/tháng. Đăng ký Hội viên
Viết nhanh hơn - Học tốt hơn
Giải phóng thời gian, khai phóng năng lực
Copied !!!