tenzil

tenzil

Vue with Phoenix

Hi All,
I am building a project in phoenix, Then i came know about vuejs, is it a good idea to mix these two. (rendered server side). Its in its beginning stage.
Thanks!

Most Liked

bulldog_in_the_dream

bulldog_in_the_dream

It can be a good idea, it all depends on what you’re trying to achieve and your needs :slight_smile:

Here’s a recipe for setting it up: https://medium.com/@bonfirealgorithm/how-to-set-up-vue-js-with-phoenix-1-4-2ed8bda7f4e0

evomedia247

evomedia247

I know that no one here or in the community expresses this, but if your rendering server side then I see no real benefit to loading in a complete js framework like react or angular or vue … all these frameworks are designed to completely hand off the UI to the js, you also have a very large dependency to download, plus trying to keep sync between your fully handed off js app and the backend model… is a pain.

Every time I have to work with server side rendered pages (via any backend like elixir and phoenix, java and thymeleaf, .net and razor etc) I use what has always been popular in .Net circles… Knockout.js

Its a tiny dependency, you simply bind the server rendered variables directly to observed ko functions (they work the same as liveviews morphdom). All knockout does is data binding, it creates watched js functions that bind UI interactions to data model changes and visa versa.

You can bind the whole thing into a viewmodel class for OO … but for phoenix I just bind each piece of data to its own separate function … when that data changes it triggers a UI diff operation, I actually create observed ko function outside a class to work the same as single functions that I feels suits phoenix and elixir well and I’m never mutating a some overarching class object which saves alot of headaches. This gives you a powerful UI data binding system that means when data is say true, the bound element appears, or a class is added or an action is triggered, and the value just is linked so if data changes the values are automatically updated everywhere… all without the massive bundle loads of react vue etc.

evomedia247

evomedia247

Here was a git repo with a simple knockout binding to demonstrate, just a simple sprinkle of ko in the main view
https://github.com/evomedia247/Phoenix-and-knockout-example.git
Its built on that example project to build chat app in 8 minutes so updates with websockets. (GitHub - dwyl/phoenix-chat-example: 💬 The Step-by-Step Beginners Tutorial for Building, Testing & Deploying a Chat app in Phoenix 1.7 [Latest] 🚀 · GitHub)

UI elements are bound to the functions via the
data-bind=“text: dataItem” to display text say
or
data-bind=“if: dataItem” to display the element if var dataItem is present and
not null

Ko watched functions are defined in the script tag..
var dataItem = ko.observable('show me ');
ko.applyBindings( );

In this repo above the message display, the class switching for user styling and the message content display is all done via knockout, I pass knockout the phoenix websocket messages directly into a watched array and the UI updates when the messages update

Where Next?

Popular in Questions Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement