Vue.js - General Discussion, Blog Posts, Wiki

We’ve got wiki’s for Elm and Bucklescript, and so as it seems Vue.js is growing in popularity in Elixir circles, it makes sense to have one for it as well :003:

Please add your thoughts about it - have you used it? Would you? What do you think?

Please also feel free to add any blog posts or other resources that would be helpful to anyone using Phoenix.


Anyone at Trust Level One can edit the wiki - simply add whatever you think needs adding to this post, then also make a new post with the info (or summary) so that the thread is bumped and people are alerted to it :023:


Website: https://vuejs.org

The Progressive JavaScript Framework

Approachable
Already know HTML, CSS and JavaScript? Read the guide and start building things in no time!

Versatile
Simple, minimal core with an incrementally adoptable stack that can handle apps of any scale.

Performant
19kb min+gzip Runtime
Blazing Fast Virtual DOM
Minimal Optimization Efforts


Blog posts

https://content.nanobox.io/phoenix-vue-js-running-in-minutes/

https://medium.com/front-end-hacking/phoenix-and-vue-js-b974d8b91cb6

https://medium.com/@jespr/create-a-simple-chat-web-app-using-phoenix-and-vue-js-bc5d82e53f9b

Forum Threads

More Vue.js threads: Topics tagged vuejs

Courses

Screencasts

https://laracasts.com/series/learn-vue-2-step-by-step

Misc

http://quasar-framework.org - framework based on Vue.js for SPA & Mobile

https://vuetifyjs.com - sweet Material Component Framework

7 Likes

One thing I’ve gotta say is its VDom implementation is fast! It is a marvel of code just looking at it, simplicity yet optimizations, a great mix.

2 Likes

This can be found elsewhere, but because it’s so important it’s worth repeating here.

Vuejs single file components don’t work very well with Brunch (the default asset compiler that comes with Phoenix). You’ll get an error each time you try to import a module from inside the .vue file Webpack, despite its shortcomings, has excellent support for Vuejs components, so if you want to use them, you should switch to Webpack.

To use webpack with Phoenix with support for .vue files (single file components):

  1. Clone your this github repo: https://github.com/straw-hat-llc/phoenix_assets_webpack into your Phoenix project, and rename it to assets/. This will be your new assets/ directory. This directory adds support for Webpack.
  2. Change the config/dev.exs to use the webpack compiler instead of brunch, according to the instructions here: https://github.com/straw-hat-llc/phoenix_assets_webpack#setup
  3. Finally, add a vue loader to the rules in your webpack.config.js. For example:
{
    test: /\.vue$/,
    loader: 'vue-loader'
}
7 Likes

I’ve used Vue.js in various ways since v1 and there’s a good community around it. It’s one of those tools that once you get a swing of it you’re wanting to use that hammer to hit every JS nail :slight_smile:

For those interested, here’s the awesome page: https://github.com/vuejs/awesome-vue

This is a nice framework based on Vue.js for SPA & Mobile: Quasar Framework

1 Like

A little note on how I use Vuejs with channels:

I like to keep my state on the client and the server stateless, but there are other possibilities. This is just the one I’m most comfortable with. The basic idea is that the client contains the current state, and the Server sends state deltas using channels (yeah, this is 2017, the server sends data to the client without being asked for). Usually

  1. The initial state JSON encoded inside a hidden DOM node (e.g. <div style="display:none">#{JSON-DATA}</div>). My vue components will just pick this state from the DOM. This saves a HTTP request to get the initial state.
  2. I use Ajax POST, PUT or DELETE requests to change data on the server according to the semantics of the verb (these changes might be sent to other clients using channels, see below)
  3. I use Ajax GET to get the full state of the component if needed. Not deltas, usually.
  4. I use channels to send state deltas from the server to the client. Usually, these deltas require some client side processing before being displayed. Fortunately, using Vuejs means that we only have to integrate the delta into the state, and the UI will update itself automatically.

This is just a warning and speculation based on something I never really tried: Note that in the setup above, theoretically we might lose a delta if it is sent after the page render on the server and before the client starts listening to events in the channel.

If this is not an option for your app, you could get the state from a GET request only after your code is listening to the channel, so that you’re sure you’re not missing any events. This will increase the page load time because of the latency of that GET request.

So, if you want to be as fast as possible, you can do something like this: 1) send the state encoded in the DOM, 3) start listening to the channel and 3) get the state from the server with an Ajax GET request, and re-render the component with the possibly updated state (while the channel is already listening). This way, you should miss no events. However, ask your friendly neighborhood javascript expert before trusting this setup with your business-critical notifications! I’m just trying to warn you of the possible dangers of the approach I described above.

3 Likes

I did not actually have much of an issue with it but I used in-string templates instead of html templates (which currently require that pre-compilation step until HTTP2 is out and standard, same issue Polymer and such have). I’d honestly say ignore the .vue file setup and just use string-templates, it is ‘slightly’ faster too on initial setup if you want another reason. ^.^

What are you calling “in-string templates”? Are you taking about templates compiled in the browser?

Nope I mean instead of using html templates I’m defining them as an inline string like (from the tutorial since it was the quick-grab):

Vue.component('todo-item', {
  props: ['todo'],
  template: '<li>{{ todo.text }}</li>'
})

Basically just copy/paste the html into the string used by a template (though I make a file of a template string and when I define the component I just call in to those for my bigger ones, that let’s me keep my html syntax highlighting in Atom).

If you use a HTML template instead then when vue loads it just gets the outerHTML of it anyway, thus converting it to a string, so it saves a short step.

Oh, that. But the only advantage is that it skips the Webpack stuff, right? All the rest is the same.

That is the only thing the webpack loader for it is useful for, just splitting the ‘vue’ files into javascript parts, and it would not surprise me if it was a babel step that you could put into brunch anyway, but I don’t like those splitters anyway so I’m happy with string literals.

Ok, thanks. I think I’ll keep using .vue files because I like the ergonomics and I’m willing to wait a couple of seconds for the initial asset compilation.

1 Like

What do you think about the experience compared to React, Elm, Bucklescript etc? Any notable advantages/disadvantages etc? Likes/dislikes? :101:

2 Likes

I started with React/Redux/React Router and switched to Vue/Vuex/Vue-Router and couldn’t be happier. It’s simpler in every way, provides the exact same benefits and the router is way better.

You can also get server-side rendering for free without a node server (although not technically the same). Just create the template as a regular HTML/EEX file as usual but mark it as an inline-template. You can then tell your component to use the existing rendered HTML as the initial component template.

I also don’t .vue single file components but that’s because I never bought into the whole “separation of technologies not separation of concerns” argument. I like to have a single CSS file used thoughout the site and I also like to separate the template from the JS logic.

I don’t use Brunch now though because you don’t get real hot code reloading and when using a state manger (Vuex) it’s very useful. I’m using Webpack now but reluctantly.

4 Likes

Having worked my way through many of the popular frontend frameworks, I can say that I really dig Vue. It really hits that Goldilocks zone by being an un-opinionted view model and ONLY a view model. It incorporates Angular 1.x-style templating with React-like components and virtual DOM. The components are totally optional but very easy to build; No learning JSX or needing a webpack step if you don’t use the optional .vue file format.

What most people seem to like about Vue is it handles the harder parts of making a single page app or frontend (data binding and event management) without being overly opinionated. There are no services to write, no controllers to inherit, no data models you have to adhere to; You’re in charge of your logic and your data. This extends to routing; There is a vue-router you can use, but it’s purely optional and totally separate so you could always write your own if you felt like it. Likewise, you can use any data management you want, including Redux.

3 Likes

I really like Vue for being super useful even if not working on a SPA or alike. It can be seamlessly added to any part of a website. So if you have that one stateful client side thing in your website you can totally use vue there and be happy. It also makes getting into the library way more simple than say react, where you first have to setup so much stuff before you can get your hands dirty. With vue the easiest setup is literally just loading the vue.js file.

I’m using laravel-mix and it does have support for vue and .vue files baked in. It’s also way easier to configure than webpack itself.

Here’s a gist on how to install it, which I just updated from the one I found previously to work with the recently released v1.x: Using Laravel-Mix with Phoenix · GitHub

2 Likes

I should also mention the vue-devtools: https://github.com/vuejs/vue-devtools

This is a real time saver during development. It allows you to see exactly what your Vue.js components are doing in real time. There is a Chrome extension as well as a new Firefox Addon.

4 Likes

Brunch has an HMR plugin. :slight_smile:

I personally don’t hot module reload at all, it is fast enough to refresh and I hold the page ‘state’ either on the server, in the URL, or in the localsession or so.

But yeah, Vue.js is very webcomponent’ish but in pure javascript with one of the fastest VDom’s out since it ‘does’ use a vdom but it uses connections similar to how Polymer works internally, so it is very fast.

1 Like

Is there a Vue equivalent to React Virtualized?

From my humble experience with React, I agree that it can be painful to get started, but it is very well suited for big SPAs and there’s a nice community (many components are open sourced).

Vue does seem to handle many things in a very simple way, but how does it scale for a large SPA? Are some hard problems like rendering big lists fast solved in Vue?

Here’s a free screencast series on vue. I don’t remember how much of the content is tied to Laravel (PHP framework) but hopefully it’s of some use.

2 Likes

Have updated the wiki with some of what you’ve all posted - please feel free to add anything you feel is missing :023: (just add to wiki then post in a new post as well)

1 Like