R
R
rusrich2019-12-16 16:47:39
Ruby on Rails
rusrich, 2019-12-16 16:47:39

What's wrong - props don't work in VUE + Ruby on Rails?

Unable to pass props to VUE.
In the vue console I get:

props:
    message: undefined

// views:
<div id="rails" class="container" data-behavior="vue">
  <app :message="<%= "Any text".to_json %>"></app>
</div>

// application.js
import Vue from 'vue'
import App from '../app.vue'

document.addEventListener('DOMContentLoaded', () => {
  const el = document.body.appendChild(document.createElement('application'))
  const app = new Vue({
  el: '[data-behavior="vue"]',
    render: h => h(App, 'app')
  })
})

// app.vue
<template>
  <div id="app">
    <p>{{ message }}</p>
  </div>
</template>

<script>
export default {
  props: ['message'],
}
</script>

<style scoped>
p {
  font-size: 2em;
  text-align: center;
}
</style>

Everything that I could find on the Internet is done something like this, only using turbolinks.
With turbolinks, the root and app components are not displayed for me, and the console does not give an error.
Where am I making a mistake?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rusrich, 2019-12-16
@rusrich

For those who have problems, here is the solution .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question