推荐关注
› Meteor
› JSLint - a JavaScript code quality tool
› jsFiddle
› D3.js
› WebStorm
推荐书目
› JavaScript 权威指南第 5 版
› Closure: The Definitive Guide
caopi

vue 异步组件的这个 require 是什么用法呢?

  •  
  •   caopi · Oct 29, 2018 · 5041 views
    This topic created in 2896 days ago, the information mentioned may be changed or developed.

    看 vue 异步组件的时候看到这个用法,但是 webpack 和 node 的官方文档都没有这个的说明,而且网上也搜不出结果。

    require(['../components/PromiseDemo'], resolve)

    6 replies  •  2018-10-29 21:38:39 +08:00
    caopi
        1
    caopi  
    OP
       Oct 29, 2018
    非常好奇
    owenliang
        2
    owenliang  
       Oct 29, 2018
    异步加载规范的样子,就是动态添加<script>标签到 HTML 中,用到某个 js 代码的时候异步加载。
    shintendo
        3
    shintendo  
       Oct 29, 2018
    这是 AMD 的写法
    iugo
        4
    iugo  
       Oct 29, 2018
    akatquas
        6
    akatquas  
       Oct 29, 2018
    低版本的 webpack 构建的时候用于异步加载 Vue 组件,常见于 Vue-Router 里面异步加载页面。

    现在可以用 `() => import('path/to/file')` 来写了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   794 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 19:26 · PVG 03:26 · LAX 12:26 · JFK 15:26
    ♥ Do have faith in what you're doing.