1 Star 0 Fork 0

Vue.js / vue-hot-reload-api

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

vue-hot-reload-api

注意: vue-hot-reload-api@2.x 仅支持 vue@2.x

Vue components 热加载API。vue-loadervueify 底层使用的就是这个。

用法

你仅会在开发一个基于 Vue components 构建工具的时候用到这个。对于普通的应用,使用 vue-loader 或者 vueify 就可以了。

// 定义一个组件作为选项对象
const myComponentOptions = {
  data () { ... },
  created () { ... },
  render () { ... }
}

// 检测 Webpack 的 HMR API
// https://doc.webpack-china.org/guides/hot-module-replacement/
if (module.hot) {
  const api = require('vue-hot-reload-api')
  const Vue = require('vue')

  // 将 API 安装到 Vue,并且检查版本的兼容性
  api.install(Vue)

  // 在安装之后使用 api.compatible 来检查兼容性
  if (!api.compatible) {
    throw new Error('vue-hot-reload-api与当前Vue的版本不兼容')
  }

  // 此模块接受热重载
  module.hot.accept()

  if (!module.hot.data) {
    // 为了将每一个组件中的选项变得可以热加载,
    // 你需要用一个不重复的id创建一次记录,
    // 只需要在启动的时候做一次。
    api.createRecord('very-unique-id', myComponentOptions)
  } else {
    // 如果一个组件只是修改了模板或是 render 函数,
    // 只要把所有相关的实例重新渲染一遍就可以了,而不需要销毁重建他们。
    // 这样就可以完整的保持应用的当前状态。
    api.rerender('very-unique-id', myComponentOptions)

    // --- 或者 ---

    // 如果一个组件更改了除 template 或 render 之外的选项,
    // 就需要整个重新加载。
    // 这将销毁并重建整个组件(包括子组件)。
    api.reload('very-unique-id', myComponentOptions)
  }
}

License

MIT

The MIT License (MIT) Copyright (c) 2015-2016 Evan You Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

🌶️ Hot reload API for Vue components 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/vuejs/vue-hot-reload-api.git
git@gitee.com:vuejs/vue-hot-reload-api.git
vuejs
vue-hot-reload-api
vue-hot-reload-api
master

搜索帮助