<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re-usable Vue.js Components with vue-loader in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/re-usable-vue-js-components-with-vue-loader/m-p/159965#M113985</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __default_attr="info" __jive_macro_name="alert" alert="info" class="jive_text_macro jive_macro_alert"&gt;&lt;SPAN style="color: #0f7198; background-color: #ffffff;"&gt;This is a personal blog post that is primarily intended for tracking my own learning rather than provided to the Alfresco Community for educational purposes. However if you find it useful, informative or have any comments on it then please comment below.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;At the end of my &lt;A _jive_internal="true" href="https://community.alfresco.com/people/ddraper/blog/2016/12/22/content-distribution-with-slots-in-vuejs" rel="nofollow noopener noreferrer"&gt;last post&lt;/A&gt; I had decided to move away from a "Content Distribution" approach for my new &lt;A href="https://vuejs.org/" rel="nofollow noopener noreferrer"&gt;Vue.js&lt;/A&gt; Alfresco client and move towards a &lt;A href="https://vuejs.org/v2/guide/single-file-components.html" rel="nofollow noopener noreferrer"&gt;single file component&lt;/A&gt; approach.&amp;nbsp;You can view the state of &lt;A href="https://github.com/draperd/AlfrescoNodeJS" rel="nofollow noopener noreferrer"&gt;my project&lt;/A&gt; at the time of writing by checking out this &lt;A href="https://github.com/draperd/AlfrescoNodeJS/releases/tag/Blog5" rel="nofollow noopener noreferrer"&gt;tag&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My original thought was that I would just move my components from the main app.js file into 3 separate files and use ES6 importing and exporting (as now handled by &lt;A href="https://webpack.js.org/" rel="nofollow noopener noreferrer"&gt;webpack&lt;/A&gt; / &lt;A href="https://babeljs.io/" rel="nofollow noopener noreferrer"&gt;babel&lt;/A&gt;). However as I read through the documentation and various blog posts (including &lt;A href="https://auth0.com/blog/create-an-app-in-vuejs-2/" rel="nofollow noopener noreferrer"&gt;the one&lt;/A&gt; I originally started&amp;nbsp;from) I realised that the recommended approach was to use &lt;A href="https://github.com/vuejs/vue-loader" rel="nofollow noopener noreferrer"&gt;vue-loader&lt;/A&gt; either via &lt;A href="https://github.com/vuejs/vueify" rel="nofollow noopener noreferrer"&gt;vueify&lt;/A&gt; or the &lt;A href="https://github.com/vuejs/vue-cli" rel="nofollow noopener noreferrer"&gt;Vue.js CLI&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This presented a minor problem in that I already had an established project and didn't want to just start over. Fortunately there are various &lt;A href="https://github.com/vuejs-templates/webpack-simple" rel="nofollow noopener noreferrer"&gt;templates&lt;/A&gt; for different build approaches (such webpack as I was using) and it was a relatively simple exercise to install the missing packages defined in the template &lt;A href="https://github.com/vuejs-templates/webpack-simple/blob/master/template/package.json" rel="nofollow noopener noreferrer"&gt;package.json&lt;/A&gt; with &lt;A href="https://yarnpkg.com/" rel="nofollow noopener noreferrer"&gt;yarn&lt;/A&gt; and copy across the additional config into my webpack.config.js file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The vue-loader module allows you to write your Vue.js components in files with a .vue extension that are essentially an HTML file containing the following 3 elements:&lt;/P&gt;&lt;PRE class="line-numbers language-markup"&gt;&lt;CODE&gt;&lt;SPAN class="language-css style token"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;&lt;/SPAN&gt;style&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;/&lt;/SPAN&gt;style&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;&lt;/SPAN&gt;template&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;/&lt;/SPAN&gt;template&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="language-javascript script token"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;&lt;/SPAN&gt;script&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;/&lt;/SPAN&gt;script&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In order to better edit these files I installed a new &lt;A href="https://github.com/vuejs/vue-syntax-highlight" rel="nofollow noopener noreferrer"&gt;syntax highlighting package&lt;/A&gt; for &lt;A href="https://www.sublimetext.com/" rel="nofollow noopener noreferrer"&gt;Sublime Text&lt;/A&gt; (which is my editor of choice).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was now able to create a .vue file for each of the 3 components. As an example the smallest is currently ListView.vue:&lt;/P&gt;&lt;PRE class="line-numbers language-markup"&gt;&lt;CODE&gt;&lt;SPAN class="language-css style token"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;&lt;/SPAN&gt;style&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;/&lt;/SPAN&gt;style&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;&lt;/SPAN&gt;template&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;&lt;/SPAN&gt;ul&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;&lt;/SPAN&gt;li&lt;/SPAN&gt; &lt;SPAN class="attr-name token"&gt;v-for&lt;/SPAN&gt;&lt;SPAN class="attr-value token"&gt;&lt;SPAN class="punctuation token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;"&lt;/SPAN&gt;item in list.entries&lt;SPAN class="punctuation token"&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;{{item.entry.name}}&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;/&lt;/SPAN&gt;li&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;/&lt;/SPAN&gt;ul&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;/&lt;/SPAN&gt;template&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="language-javascript script token"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;&lt;/SPAN&gt;script&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;export&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;default&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; props&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'list'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;/&lt;/SPAN&gt;script&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A couple of things that I noticed were that the file name needs to match how I use it as a custom element. I discovered that is is necessary to define your component names in JavaScript &amp;nbsp;in camel-case (i.e. "ListView") but that you can refer to them in the template as lisp-case (also sometimes referred to as "kebab-case" or "spinal-case") (i.e. "List-View").&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As predicted I was able to get rid of my global bus (that I had to use with the content distribution approach) so the volume of code actually reduced.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The main disadvantage that I can see is that my outer component (List) now directly declares it's sub-components as both dependencies and in it's template:&lt;/P&gt;&lt;PRE class="line-numbers language-markup"&gt;&lt;CODE&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;&lt;/SPAN&gt;template&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;&lt;/SPAN&gt;div&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;&lt;/SPAN&gt;Toolbar&lt;/SPAN&gt; &lt;SPAN class="attr-name token"&gt;:list&lt;/SPAN&gt;&lt;SPAN class="attr-value token"&gt;&lt;SPAN class="punctuation token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;"&lt;/SPAN&gt;list&lt;SPAN class="punctuation token"&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class="attr-name token"&gt;@pageForward&lt;/SPAN&gt;&lt;SPAN class="attr-value token"&gt;&lt;SPAN class="punctuation token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;"&lt;/SPAN&gt;pageForward&lt;SPAN class="punctuation token"&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class="attr-name token"&gt;@pageBack&lt;/SPAN&gt;&lt;SPAN class="attr-value token"&gt;&lt;SPAN class="punctuation token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;"&lt;/SPAN&gt;pageBack&lt;SPAN class="punctuation token"&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;/&lt;/SPAN&gt;Toolbar&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;&lt;/SPAN&gt;List-View&lt;/SPAN&gt; &lt;SPAN class="attr-name token"&gt;:list&lt;/SPAN&gt;&lt;SPAN class="attr-value token"&gt;&lt;SPAN class="punctuation token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;"&lt;/SPAN&gt;list&lt;SPAN class="punctuation token"&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;/&lt;/SPAN&gt;List-View&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;/&lt;/SPAN&gt;div&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="token tag"&gt;&lt;SPAN class="punctuation token"&gt;&amp;lt;/&lt;/SPAN&gt;template&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, Vue.js does provide a way in which components can be extended (through what they call &lt;A href="https://vuejs.org/v2/guide/mixins.html" rel="nofollow noopener noreferrer"&gt;mixins&lt;/A&gt;) which should make it possible to extend List and update the template to use a different view component for example.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 22 Dec 2016 08:51:14 GMT</pubDate>
    <dc:creator>ddraper</dc:creator>
    <dc:date>2016-12-22T08:51:14Z</dc:date>
    <item>
      <title>Re-usable Vue.js Components with vue-loader</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/re-usable-vue-js-components-with-vue-loader/m-p/159965#M113985</link>
      <description>This is a personal blog post that is primarily intended for tracking my own learning rather than provided to the Alfresco Community for educational purposes. However if you find it useful, informative or have any comments on it then please comment below.At the end of my last post I had decided to mo</description>
      <pubDate>Thu, 22 Dec 2016 08:51:14 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/re-usable-vue-js-components-with-vue-loader/m-p/159965#M113985</guid>
      <dc:creator>ddraper</dc:creator>
      <dc:date>2016-12-22T08:51:14Z</dc:date>
    </item>
  </channel>
</rss>

