Skip to content

Make intro more newbie-friendly #241

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ We will be using NPM throughout the guide, but feel free to use [Yarn](https://y

## Rendering a Vue Instance

Save the following code in a `.js` file, for example `render1.js`

``` js
// Step 1: Create a Vue instance
const Vue = require('vue')
Expand All @@ -41,6 +43,20 @@ renderer.renderToString(app).then(html => {
})
```

To run the code, from the prompt console of your OS execute

``` bash
node .\render1.js
```

You should see the following output. Row is duplicated if you keep both `rendered.renderToString(..)`, otherwise you see only one row of output.

```
<div data-server-rendered="true">Hello World</div>
<div data-server-rendered="true">Hello World</div>
```


## Integrating with a Server

It is pretty straightforward when used inside a Node.js server, for example [Express](https://expressjs.com/):
Expand All @@ -49,6 +65,9 @@ It is pretty straightforward when used inside a Node.js server, for example [Exp
npm install express --save
```
---

Save the following code in a `.js` file, for example `render2.js`

``` js
const Vue = require('vue')
const server = require('express')()
Expand Down Expand Up @@ -80,6 +99,20 @@ server.get('*', (req, res) => {
server.listen(8080)
```

To run the code, from the prompt console of your OS execute

``` bash
node .\render2.js
```

Then open your browser at [http://localhost:8080](http://localhost:8080)

You should see no output in the console, but you'll see what follows in your browser

```
The visited URL is: /
```

## Using a Page Template

When you render a Vue app, the renderer only generates the markup of the app. In the example we had to wrap the output with an extra HTML page shell.
Expand Down