-
-
Notifications
You must be signed in to change notification settings - Fork 5k
update lazy-loading Chinese docs #1627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
docs/zh-cn/advanced/lazy-loading.md
Outdated
@@ -4,25 +4,28 @@ | |||
|
|||
结合 Vue 的 [异步组件](http://vuejs.org/guide/components.html#Async-Components) 和 Webpack 的 [code splitting feature](https://doc.webpack-china.org//guides/code-splitting-async/#require-ensure-/), 轻松实现路由组件的懒加载。 | |||
|
|||
我们要做的就是把路由对应的组件定义成异步组件: | |||
首先,可以将 async 组件定义为返回一个 Promise 的工厂函数(该函数应该 resolve 组件本身): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
首先,可以将 async 异步 (注:上下文统一) 组件定义为返回一个 Promise 的工厂函数(该函数 返回的Promise 应该 resolve 组件本身):
docs/zh-cn/advanced/lazy-loading.md
Outdated
|
||
|
||
``` js | ||
const Foo = () => Promise.resolve({ /* component definition */ }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
component definition => 组件定义对象
docs/zh-cn/advanced/lazy-loading.md
Outdated
const Foo = () => Promise.resolve({ /* component definition */ }) | ||
``` | ||
|
||
第二,在 webpack 2中,我们可以使用[动态 import](https://github.com/tc39/proposal-dynamic-import)语法来定义 code split 点(split point): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
来定义code split 代码分块 点(split point)
docs/zh-cn/advanced/lazy-loading.md
Outdated
``` | ||
|
||
这里还有另一种代码分块的语法,使用 AMD 风格的 require,于是就更简单了: | ||
>注意:如果您使用的是 babel,你将需要添加[syntax-dynamic-import](http://babeljs.io/docs/plugins/syntax-dynamic-import/)插件,babel 可以正确地解析语法。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
才能使 babel 可以正确地解析语法
docs/zh-cn/advanced/lazy-loading.md
Outdated
### 把组件按组分块 | ||
|
||
有时候我们想把某个路由下的所有组件都打包在同个异步 chunk 中。只需要 [给 chunk 命名](https://webpack.js.org/guides/code-splitting-require/#chunkname),提供 `require.ensure` 第三个参数作为 chunk 的名称: | ||
有时候我们想把某个路由下的所有组件都打包在同个异步 chunk 中。只需要使用 [命名 chunk](https://webpack.js.org/guides/code-splitting-require/#chunkname),一个特殊的注释语法来提供chunk name(需要webpack > 2.4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在同个异步 chunk 中 -> 在同个异步块(chunk)中
注:下文中出现了“异步块”,这里应该提及
@fnlctrl |
docs/zh-cn/advanced/lazy-loading.md
Outdated
|
||
我们要做的就是把路由对应的组件定义成异步组件: | ||
首先,可以将异步组件定义为返回一个 Promise 的工厂函数(该函数应该 resolve 组件本身): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里漏改了:joy:
该函数应该 resolve 组件本身 => 该函数返回的Promise应该 resolve 组件本身
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看漏了,好了
No description provided.