Skip to content

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

Merged
merged 3 commits into from
Jul 25, 2017
Merged

update lazy-loading Chinese docs #1627

merged 3 commits into from
Jul 25, 2017

Conversation

Binaryify
Copy link
Contributor

No description provided.

@posva posva requested a review from fnlctrl July 24, 2017 14:32
@@ -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 组件本身):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

首先,可以将 async 异步 (注:上下文统一) 组件定义为返回一个 Promise 的工厂函数(该函数 返回的Promise 应该 resolve 组件本身):



``` js
const Foo = () => Promise.resolve({ /* component definition */ })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

component definition => 组件定义对象

const Foo = () => Promise.resolve({ /* component definition */ })
```

第二,在 webpack 2中,我们可以使用[动态 import](https://github.com/tc39/proposal-dynamic-import)语法来定义 code split 点(split point):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

来定义code split 代码分块 点(split point)

```

这里还有另一种代码分块的语法,使用 AMD 风格的 require,于是就更简单了:
>注意:如果您使用的是 babel,你将需要添加[syntax-dynamic-import](http://babeljs.io/docs/plugins/syntax-dynamic-import/)插件,babel 可以正确地解析语法。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

才能使 babel 可以正确地解析语法

### 把组件按组分块

有时候我们想把某个路由下的所有组件都打包在同个异步 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在同个异步 chunk 中 -> 在同个异步块(chunk)中

注:下文中出现了“异步块”,这里应该提及

@Binaryify
Copy link
Contributor Author

@fnlctrl
修改完毕


我们要做的就是把路由对应的组件定义成异步组件:
首先,可以将异步组件定义为返回一个 Promise 的工厂函数(该函数应该 resolve 组件本身):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里漏改了:joy:
该函数应该 resolve 组件本身 => 该函数返回的Promise应该 resolve 组件本身

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看漏了,好了

@fnlctrl fnlctrl merged commit b2f2745 into vuejs:dev Jul 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants