<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kevin Cocquyt</title>
    <description>The latest articles on DEV Community by Kevin Cocquyt (@keco39).</description>
    <link>https://dev.to/keco39</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F94577%2Fba301482-9d4c-4a5f-bfc8-d474f49d7e4a.png</url>
      <title>DEV Community: Kevin Cocquyt</title>
      <link>https://dev.to/keco39</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/keco39"/>
    <language>en</language>
    <item>
      <title>Vue SFC’s in an ASP.NET MVC app</title>
      <dc:creator>Kevin Cocquyt</dc:creator>
      <pubDate>Fri, 08 Feb 2019 13:43:40 +0000</pubDate>
      <link>https://dev.to/keco39/vue-sfcs-in-an-aspnet-mvc-app-3e45</link>
      <guid>https://dev.to/keco39/vue-sfcs-in-an-aspnet-mvc-app-3e45</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F768%2F1%2AvVQ6x4M-2gNQymyR5t5GXA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F768%2F1%2AvVQ6x4M-2gNQymyR5t5GXA.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inspired by &lt;a href="https://medium.com/u/d3049ae2fd3a" rel="noopener noreferrer"&gt;Cristi Jora&lt;/a&gt; and this article: &lt;a href="https://medium.com/corebuild-software/vue-js-and-net-mvc-b5cede228626" rel="noopener noreferrer"&gt;https://medium.com/corebuild-software/vue-js-and-net-mvc-b5cede22862&lt;/a&gt;, I went on and tried to add the same functionalities in our boilerplate solution for future projects.&lt;/p&gt;

&lt;p&gt;Between the time the article was posted and when I started my implementation, webpack went from v3 to v4 and Vue introduced the vue-template-compiler (additional to the vue-loader). Luckilly, most of the workings stayed the same… Writing SFC’s as well as adding them to your page with the created custom tags. The biggest challenge was moving over the webpack configuration (and doing something extra in my case) and that’s what I’m going to talk about.&lt;/p&gt;

&lt;p&gt;When webpack went from v3 to v4, lots of the configuration settings were made easier (coming out of the box, like production mode which minifies your code), so you will see a ‘more or less’ slimmed down version of the configuration file as used in the mentioned article.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const path = require("path");
const fs = require("fs");
const VueLoaderPlugin = require("vue-loader/lib/plugin");

const appBasePath = "./js/components/";
const jsEntries = {};

fs.readdirSync(appBasePath).forEach(name =\&amp;gt; {
 var indexFile = `${appBasePath}${name}/index.js`;
 if (fs.existsSync(indexFile)) {
 jsEntries[name] = indexFile;
 }
});

module.exports = {
 entry: jsEntries,
 output: {
 path: path.resolve(\_\_dirname, "../dist/js/components"),
 filename: "[name].js"
 },
 resolve: {
 alias: {
 vue$: "vue/dist/vue.esm.js"
 }
 },
 module: {
 rules: [
 {
 test: /\.vue$/,
 use: {
 loader: "vue-loader",
 options: {
 js: "babel-loader"
 }
 }
 },
 {
 test: /\.js$/,
 exclude: /node\_modules/,
 use: {
 loader: "babel-loader",
 options: {
 presets: ["[@babel/preset-env](http://twitter.com/babel/preset-env)"]
 }
 }
 },
 {
 test: /\.(css|scss)$/,
 use: ["vue-style-loader", "style-loader", "css-loader", "sass-loader"]
 }
 ]
 },
 plugins: [new VueLoaderPlugin()],
 optimization: {
 splitChunks: {
 cacheGroups: {
 commons: {
 test: /[\\/]node\_modules[\\/]/,
 name: "vendors",
 chunks: "all"
 }
 }
 }
 },
 devtool: "source-map"
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, it starts out with the same loop creating the entries (see mentioned article for the detailed information). For output, I chose a subfolder ‘components’ within my ‘dist’ folder as it’s only used for compiling Vue components. After that, do not (!) forget the ‘resolve’ setting as, because I thought it wouldn’t be, it cost me half a day to figure out why my compiled .js files were not rendering my components. The ‘module’ settings that follow are more or less the same, except for some options here and there (adding an additional package or a simplified Babel 7 setup). ‘Plugins’ is a new part and introduced since one of the latest vue-loader updates. And, maybe the part where I’m most happy about is the optimization (see separate section underneath).&lt;/p&gt;

&lt;h3&gt;
  
  
  Optimization
&lt;/h3&gt;

&lt;p&gt;When creating a .js file, all of the included SFC’s and imported node modules are bundled and minified into one big .js file. As I don’t need every component on every page, I create a .js file per page using the jsEntries logic. The downside with that is that every .js file would be bundled up with the Vue runtime meaning an extra +/- 100 KB per file. Luckilly, you can do some optimizations by creating an extra file (‘vendors.js’ in my case), containing all the common node modules that are used in the Vue components making for only one (cachable) file. That file can then be added in your _Layout page and the other .js files can be added per page resulting in a lot less KB’s that have to be downloaded by your users and making the components load faster too.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F599%2F1%2A7XL6SNh54FaPH8-cLAoAUg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F599%2F1%2A7XL6SNh54FaPH8-cLAoAUg.png"&gt;&lt;/a&gt;Without decoupling the common node modules, every page file would be +104KB&lt;/p&gt;

&lt;h3&gt;
  
  
  Cache busting
&lt;/h3&gt;

&lt;p&gt;When you add the JS files to your webpages, those will be cached by the browser and not be updated when a new version arrives (as it’s cached on the name, which did not change). As you’re not using the built-in .NET MVC bundling module, this also means the automated cache busting technique is not applied (changing/concatenating your JS files with a hash which changes when you change the JS files). For that, you will have to implement your own style of cache busting and more information can be found here: &lt;a href="https://madskristensen.net/blog/cache-busting-in-aspnet/" rel="noopener noreferrer"&gt;https://madskristensen.net/blog/cache-busting-in-aspnet/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I prefer the solution with the assembly version (&lt;a href="https://madskristensen.net/blog/cache-busting-in-aspnet/#546c01e8-b3c7-4b63-a863-a47de3dc1507" rel="noopener noreferrer"&gt;https://madskristensen.net/blog/cache-busting-in-aspnet/#546c01e8-b3c7-4b63-a863-a47de3dc1507&lt;/a&gt;) even when it means a querystring is added as it’s not best practice for Google Page Speed. Standard .NET MVC bundling is doing the exact same thing after all…&lt;/p&gt;

&lt;p&gt;And that’s about it if you want to add Vue SFC’s to your existing ASP.NET MVC projects. I had a blog post before about Vue components (non-SFC) but it bothered me that I couldn’t use the styling bit of SFC’s so I searched on and finally came up with a solution I’m happy about.&lt;/p&gt;

&lt;p&gt;For those interested, I added the necessary files to a github repo so you can just copy-paste the stuff from there: &lt;a href="https://github.com/KevinCocquyt39/mvc-vue-webpack4" rel="noopener noreferrer"&gt;https://github.com/KevinCocquyt39/mvc-vue-webpack4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>aspnetmvc</category>
      <category>vue</category>
    </item>
    <item>
      <title>I18N in Vue Components for ASP.NET MVC apps</title>
      <dc:creator>Kevin Cocquyt</dc:creator>
      <pubDate>Tue, 21 Aug 2018 21:05:39 +0000</pubDate>
      <link>https://dev.to/keco39/i18n-in-vue-components-for-aspnet-mvc-apps-50i3</link>
      <guid>https://dev.to/keco39/i18n-in-vue-components-for-aspnet-mvc-apps-50i3</guid>
      <description>&lt;p&gt;I18N (internationalization) may not a big deal when you need to write English-only apps but in my bilingual country, leaving that aspect out is never an option. As I’m working with Vue a lot lately, I tried to create my first form with translated labels.&lt;/p&gt;

&lt;p&gt;The technology used is ASP.NET MVC so no Webpack and no use of plug-ins and this is what I found 100% of the time when searching for ‘Vue + i18n’: the usage of a plug-in.&lt;/p&gt;

&lt;p&gt;After reading the source code for that plug-in on GitHub, I created something I could use for my MVC projects. What came back a lot, in the different articles I found about it, was the use of a filter to show translations for a given label and that’s what I went with and will describe in the second part of this blog-post.&lt;/p&gt;

&lt;p&gt;You may remember my first blog-post describing the creation of a Vue-component. If not, you may want to read that one first: &lt;a href="https://dev.to/kevincocquyt39/vue-components-in-an-aspnet-mvc-app-11jd"&gt;https://medium.com/@kevin_cocquyt/vue-components-in-an-asp-net-mvc-app-e9eb0004c054&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 — Creating a component
&lt;/h3&gt;

&lt;p&gt;I created a component containing a title, a table element with header-elements and one row with data. As the header labels need to be translated, a default value is used followed by a filter in which the right translation for a given label is retrieved. That filter is then specified within the component itself and within that function, a list of translations is searched for the label that was passed as a parameter and, when found, the value-property for that list-item is returned, otherwise, the passed value (the value before the pipe-symbol) is returned. I need to pass the ‘ml’-list (more on that later) for each call to the filter as filters do not allow the usage of data-properties within them (meaning ‘this.ml’ only returns a null instead of the actual value, ‘ml’ stands for multilang in my case).&lt;/p&gt;

&lt;p&gt;I could have named my component ‘vue-table-component’, which would be more appropriate but I’m too lazy to change my screenshots (and it’s 11PM already) :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A0TFnAOHQBw9MkEVtDam77A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A0TFnAOHQBw9MkEVtDam77A.png"&gt;&lt;/a&gt;using a filter to find the right translation, defaulting to the initial value&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2 — Registering the component
&lt;/h3&gt;

&lt;p&gt;Registering is necessary for two things: the first is making sure you can use the component in your HTML and second, you need to be able to refer to that component to be able to pass in the translations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F668%2F1%2Av4H8tXixz0he1yAIaVYsJQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F668%2F1%2Av4H8tXixz0he1yAIaVYsJQ.png"&gt;&lt;/a&gt;registration of the component&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3 — Passing in the translations
&lt;/h3&gt;

&lt;p&gt;As the component was registered and assigned to a variable (can be let, or even const instead of var), you can now refer to the data-properties of that component.&lt;/p&gt;

&lt;p&gt;The ‘main’ div is registered as the element in which the component will be loaded. ‘vue-form-component’ is the name of the created component. ‘title’ is a data-property and ref is the ‘reference name’ that can be used within your JavaScript or TypeScript (main.js is the file that contains the creation and registration).&lt;/p&gt;

&lt;p&gt;At the bottom, an array of objects is assigned to the ‘ml’-property with two properties per object, each one appropriately named but you can name them in any way you like, as long as you then change the filter-function accordingly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A_-NRQa4Oy1SeHgx8cCzzag.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A_-NRQa4Oy1SeHgx8cCzzag.png"&gt;&lt;/a&gt;passing a list of translations&lt;/p&gt;

&lt;p&gt;These look like fixed values of course but, for example, in my professional projects, I use an MVC HTML-extension like @Html.Translation(“number”) meaning the right translation will be retrieved from our database (using the set language) so one or your added objects could then look like:&lt;/p&gt;

&lt;p&gt;{ name: “label.number”, value: “@Html.Translation(“number”)” }&lt;/p&gt;

&lt;p&gt;Make sure the strings that come back from your database are encoded as they will be used within scripting (single/double quotes).&lt;/p&gt;

&lt;p&gt;After passing the translations to the referenced property, the multilang-labels are known within your component and searchable via the filter-function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Result
&lt;/h3&gt;

&lt;p&gt;In the rendered HTML, only the second and third labels were translated whilst the first label, as there was no translation in the ‘ml’-list for it, only displays its default value (the string before the pipe-symbol).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AsgSRaXQjioO2mckG_DJXxQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AsgSRaXQjioO2mckG_DJXxQ.png"&gt;&lt;/a&gt;HTML rendering&lt;/p&gt;

&lt;p&gt;And that’s it.&lt;/p&gt;

&lt;p&gt;Thanks to the writers of the plug-in and the ones of the articles I found to push me in the right direction, and thanks to myself for coming up with a passable solution, so I can sleep again at night (yes, these types of things keep me up!)&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

&lt;p&gt;PS: This is A solution, so I guess not THE solution, so if there are better ones for this scenario, please share yours in the comment section.&lt;/p&gt;

&lt;p&gt;EDIT: Internet Explorer can be a real pain for web developers. It's at it again as it doesn't support the array.find() method. For that, inject the pollyfill script (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find&lt;/a&gt;) somewhere in your JS and you're good to go. Or use lodash (&lt;a href="https://lodash.com" rel="noopener noreferrer"&gt;https://lodash.com&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;EDIT 2: As I’m still learning the in’s &amp;amp; out’s of Vue, I learned about global filters and thought it was awesome. For that, I tried to implement this for my translations and it worked like a charm! What I did is creating a new file called ‘component-filters.ts’ with the following code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2AAxBKv82KpPv400y4sR1U3A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2AAxBKv82KpPv400y4sR1U3A.png"&gt;&lt;/a&gt;&lt;/p&gt;
/js/component-filters.ts



&lt;p&gt;And add that script-file to the bundle:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2APrDv7cWm6E0FzSrQdR0lvA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2APrDv7cWm6E0FzSrQdR0lvA.png"&gt;&lt;/a&gt;&lt;/p&gt;
bundling



&lt;p&gt;Then just remove the ‘translation’ filter from the component and everything keeps on working.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>i18n</category>
      <category>aspnetmvc</category>
      <category>vue</category>
    </item>
    <item>
      <title>Vue Components in an ASP.NET MVC app</title>
      <dc:creator>Kevin Cocquyt</dc:creator>
      <pubDate>Mon, 20 Aug 2018 20:24:13 +0000</pubDate>
      <link>https://dev.to/keco39/vue-components-in-an-aspnet-mvc-app-11jd</link>
      <guid>https://dev.to/keco39/vue-components-in-an-aspnet-mvc-app-11jd</guid>
      <description>&lt;p&gt;I’ve been using Vue JS (&lt;a href="https://vuejs.org" rel="noopener noreferrer"&gt;https://vuejs.org&lt;/a&gt;) for close to a year in a couple of my professional projects but never in the preferred way, meaning it still consisted of static HTML, Vue instances only containing the scripting and dedicated SASS-files for its styling. As components is the go-to method for web development nowadays, I really wanted to integrate this way of working into my MVC app(s).&lt;/p&gt;

&lt;p&gt;There is SFC’s (single file components) but as you need Vue Loader and Webpack for that, this was not a real option for projects still using MSBuild and the standard ways of bundling. So on went my search but I wasn’t able to find a good centralized explanation on how to put it all together. Most blogs talk about using them in SPA’s and such with Webpack but never about using them in legacy projects… That’s why, after finally having figured out a good implementation, I planned to write a single blog-post about it hoping to save other people some time that could be spend on more lucrative features.&lt;/p&gt;

&lt;p&gt;[UPDATE 2019/02/08] I didn’t stop to search for an SFC solution, found it and wrote about it in here… &lt;a href="https://dev.to/keco39/vue-sfcs-in-an-aspnet-mvc-app-3e45"&gt;https://dev.to/keco39/vue-sfcs-in-an-aspnet-mvc-app-3e45&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, I’ll start with the 2 steps that are only needed the first time you would like to add support for Vue-components to your project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 — Setting up TypeScript
&lt;/h3&gt;

&lt;p&gt;I use TypeScript (&lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;https://www.typescriptlang.org&lt;/a&gt;) as my main scripting-language. Not only does it give you strong typing and improved intellisense but it also makes sure your templating strings will still work if you open your website in Internet Explorer. The reason for this is, when using a template string (read &lt;a href="https://vuejs.org/v2/guide/components.html" rel="noopener noreferrer"&gt;https://vuejs.org/v2/guide/components.html&lt;/a&gt; for more details) in multiple lines, you will need backticks for that. As backticks are an ES6 feature, Internet Explorer would not recognize the character in your template string and thus fail to render your component. Make sure you target ES5 within the tsconfig.json file so all backticks will be transpiled into single quotes, thus gaining support for older browsers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2 — Add a reference to the Vue library
&lt;/h3&gt;

&lt;p&gt;As with all third-party libraries, you need to add Vue to the bottom of your webpage, above the scripts that will create and register your components (eg. &lt;a href="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js" rel="noopener noreferrer"&gt;https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Once these 2 steps are done, you never have to look at them again except for when you start a new project.&lt;/p&gt;

&lt;p&gt;And now on to the cool bits, creating and registering your Vue components. For that, there are 4 steps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 — Creating a component
&lt;/h3&gt;

&lt;p&gt;I have a folder called ‘/js/components’ in which a TypeScript-file is created with a filename starting with vue-*, followed by the name of your component (preferably, the following words are also separated by a hyphen). How to create your component can be found in the official documentation on &lt;a href="https://vuejs.org/v2/guide/components-registration.html" rel="noopener noreferrer"&gt;https://vuejs.org/v2/guide/components-registration.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F834%2F1%2AyU2YFMe03drlOojWc-iNbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F834%2F1%2AyU2YFMe03drlOojWc-iNbg.png"&gt;&lt;/a&gt;/js/components/vue-component.ts&lt;/p&gt;

&lt;p&gt;I prefer to assign the returning value to a variable and the reason for that will be explained in the second step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2 — Registering your component
&lt;/h3&gt;

&lt;p&gt;As the created component is still unknown within your web app, you need to register it by initializing Vue. For this, I create a different file within my ‘/js’ folder called component-loader.ts, making it clear this file is meant for registering (thus loading) your components using Vue.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F590%2F1%2Aom-JifInOvzJ8aIjVxUe9g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F590%2F1%2Aom-JifInOvzJ8aIjVxUe9g.png"&gt;&lt;/a&gt;/js/component-loader.ts&lt;/p&gt;

&lt;p&gt;It is not necessary to use the option ‘components’ (passing an object containing all components that you want to register) as, without it, all of your components will be known within your web project instead of only the list that is passed. I prefer explicit naming as I sometimes create several instances for different kinds of components (eg. myFormComponents, myGalleryComponents etc.). As for the selector ‘#main’, this will be the semantic element (mostly a div) in which the component(s) will be loaded.&lt;/p&gt;

&lt;p&gt;As of now the HTML-tag ‘vue-component’ can be used in your project.&lt;/p&gt;

&lt;p&gt;You noticed I assigned the value of the instance to a new variable and that is because of the following (handy) feature… Let’s say you use the tag as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A0LgeFlBfFEJ-dQAFSHWQfQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A0LgeFlBfFEJ-dQAFSHWQfQ.png"&gt;&lt;/a&gt;Vue component usage in HTML document&lt;/p&gt;

&lt;p&gt;The HTML-tag ‘vue-component’ (the given name when creating the component) is created with a name attribute (data property) and a reference-name to that component. With that reference, it’s now possible to use the variable to which you assigned the value of the instance, followed by $refs, followed by the ‘reference name’ , followed by a property that was configured when creating the component. Eg.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F723%2F1%2AV7xn0_oELzjnPyyxmMK6uA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F723%2F1%2AV7xn0_oELzjnPyyxmMK6uA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3 — Bundling
&lt;/h3&gt;

&lt;p&gt;As bundling is still mandatory to keep your scripting footprint as low as possible, you need to minify and bundle up the resulting JavaScript-files (transpiled from TypeScript). I added, in this case, the component- and the loader-file to the bundle and placed them at the bottom of the HTML-page, just below the reference to the third-party Vue library.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2Aus7Pf82Ijkq1ec_FV9wXPw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2Aus7Pf82Ijkq1ec_FV9wXPw.png"&gt;&lt;/a&gt;Javascript bundle with components (.NET functionality)&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4 — Git
&lt;/h3&gt;

&lt;p&gt;To make sure the transpiled JavaScript-files won’t be added to your git-repository, add those files to a .gitignore file. The Javascript-files are better off being created by a CI/CD-build.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F310%2F1%2AdR05mGavMrOs9u_UaZNzzA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F310%2F1%2AdR05mGavMrOs9u_UaZNzzA.png"&gt;&lt;/a&gt;.gitignore rules to exclude JavaScript files&lt;/p&gt;

&lt;p&gt;As a result, you now have a working Vue-component with scripting and HTML bundled into one file, leaving out only the styling bit which still goes into a dedicated CSS/SASS-file. Hopefully, this can be combined one day…&lt;/p&gt;

&lt;p&gt;Another challenging feature was using i18n as most sources only talk about the plug-in, not an option, but that’s something for my next blog-post.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>aspnetmvc</category>
      <category>vue</category>
    </item>
  </channel>
</rss>
