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

Server-side render Vue components? #43

Open
joekrump opened this issue Jul 12, 2023 · 0 comments
Open

Server-side render Vue components? #43

joekrump opened this issue Jul 12, 2023 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@joekrump
Copy link
Collaborator

joekrump commented Jul 12, 2023

Open questions

  1. Is it possible to fetch the template from the rails server using an html endpoint which renders the view that maybe written in .html.erb and also has Vue directive markup on it? Ex.
<!-- show.html.erb -->

<template>
  <h1><%= model.name %></h1>
  <button @click="doSomething">Click me!</button>
</template>
  • Where would the doSomething function be defined in this case?

Psuedocode

Here's a rough idea based on my understanding so far

// hit an endpoint on the rails server that renders the `show.html.erb` _(see above)_
const res = await fetch('/model/show.html')

Vue.createApp({
  template: await res.text(), // https://developer.mozilla.org/en-US/docs/Web/API/Response/text
  // Something here to define the doSomething function?
})
  1. Is it valid to include <script> tags with imports, etc within the .html.erb file that is rendered and then processed by Vue as the template option passed to createApp?

Ex. Could I do this?

<!-- show.html.erb -->

<template>
  <h1><%= model.name %></h1>
  <button @click="doSomething">Click me!</button>
</template>

<script setup>
  const doSomething = () => {
    alert("Hello world!")
  };
</script>
@joekrump joekrump added enhancement New feature or request help wanted Extra attention is needed labels Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant