Skip to content
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

Vue docs update #661

Merged
Merged
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
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ document.addEventListener('DOMContentLoaded', () => {

#### Vue

Add the data as attributes in the element you are going to use (or any other element for that matter).

```erb
<%= content_tag :div,
id: "hello-vue",
Expand All @@ -614,17 +616,50 @@ document.addEventListener('DOMContentLoaded', () => {
<% end %>
```

This should produce the following HTML:

```html
<div id="hello-vue" data-name="David" data-message="Hello!"></div>
<div id="hello-vue" data="{&quot;message&quot;:&quot;Hello!&quot;,&quot;name&quot;:&quot;David&quot;}"></div>
```

Now, modify your Vue app to expect the properties.

```html
<template>
<div id="app">
<p>{{test}}{{message}}{{name}}</p>
</div>
</template>

<script>
export default {
// A child component needs to explicitly declare
// the props it expects to receive using the props option
// See https://vuejs.org/v2/guide/components.html#Props
props: ["message","name"],
data: function () {
return {
test: 'This will display: ',
}
}
}
</script>

<style>
</style>

```


```js
// Render component with props

document.addEventListener('DOMContentLoaded', () => {

// Get the properties BEFORE the app is instantiated
const node = document.getElementById('hello-vue')
const props = JSON.parse(node.getAttribute('data'))

// Render component with props
new Vue({
render: h => h(App, { props })
}).$mount('#hello-vue');
Expand Down