Vue Web App

Posted on  by admin

This article requires the Vue.js template, which is available starting in Visual Studio 2017 version 15.8. You must have Visual Studio installed and the Node.js development workload. If you haven't already installed Visual Studio 2019, go to the Visual Studio downloads page to install it for free.

Prerequisites:

If you haven't already installed Visual Studio 2017, go to the Visual Studio downloads page to install it for free.

If you need to install the workload but already have Visual Studio, go to Tools > Get Tools and Features.., which opens the Visual Studio Installer. Choose the Node.js development workload, then choose Modify. You must have the Node.js runtime installed. If you don't have it installed, we recommend you install the LTS version from the Node.js website for best compatibility with outside frameworks and libraries.

Objective: To setup a local Vue development environment, create a starter app, and understand the basics of how it works.

A clearer Vue

Node.js is built for 32-bit and 64-bit architectures. The Node.js tools in Visual Studio, included in the Node.js workload, support both versions. Only one is required and the Node.js installer only supports one being installed at a time.

In general, Visual Studio automatically detects the installed Node.js runtime. If it does not detect an installed runtime, you can configure your project to reference the installed runtime in the properties page (after you create a project, right-click the project node, choose Properties, and set the Node.exe path). You can use a global installation of Node.js or you can specify the path to a local interpreter in each of your Node.js projects. If you don't have the Node.js runtime already installed, install the LTS version from the Node.js website.

For more information, see the prerequisites. Open Visual Studio. Create a new project. Press Esc to close the start window. Type Ctrl + Q to open the search box, type Basic Vue.js, then choose Basic Vue.js Web application (either JavaScript or TypeScript). In the dialog box that appears, type the name basic-vuejs, and then choose Create. From the top menu bar, choose File > New > Project.

In the left pane of the New Project dialog box, expand JavaScript or TypeScript, then choose Node.js. In the middle pane, choose Basic Vue.js Web application, type the name basic-vuejs, and then choose OK. If you don't see the Basic Vue.js Web application project template, you must add the Node.js development workload.

Installation

For detailed instructions, see the Prerequisites. Visual Studio creates the new project. The new project opens in Solution Explorer (right pane). Check the Output window (lower pane) for progress on installing the npm packages required for the application. In Solution Explorer, open the npm node and make sure that all the listed npm packages are installed. If any packages are missing (exclamation point icon), you can right-click the npm node and choose Install Missing npm Packages.

Initializing a new project

Take a look at Solution Explorer in the right pane. Highlighted in bold is your project, using the name you gave in the New Project dialog box. On disk, this project is represented by a .njsproj file in your project folder.

  1. At the top level is a solution, which by default has the same name as your project. A solution, represented by a .sln file on disk, is a container for one or more related projects.
  2. The npm node shows any installed npm packages. You can right-click the npm node to search for and install npm packages using a dialog box.
  3. If you want to install npm packages or run Node.js commands from a command prompt, right-click the project node and choose Open Command Prompt Here. In Solution Explorer, right-click any folder such as the src/components folder, and then choose Add > New Item.
  4. Select either JavaScript Vue Single File Component or TypeScript Vue Single File Component, and then click Add. Visual Studio adds the new file to the project. Next, choose Build > Build Solution to build the project.
  5. Check the Output window to see build results, and choose Build from the Show output from list. (TypeScript project only) From Visual Studio, choose Build > Clean Solution.
  6. Next, choose Build > Build Solution to build the project. Check the Output window to see build results, and choose Build from the Show output from list. Press Ctrl+F5 (or Debug > Start Without Debugging) to run the application. In the console, you see a message Starting Development Server. Then, the app opens in a browser.
  7. If you don't see the running app, refresh the page. Close the web browser. As websites continue to grow in complexity and design, JavaScript frameworks have become a popular tool for maximizing developer productivity.

One of the most popular JavaScript frameworks is Vue.js. We'll start this interactive Vue.js tutorial by using Vue to create a web app with no complicated build tools.

Then we'll utilize command-line tools to empower your Vue app to scale to enterprise level. Next, we'll develop your app with modular component architecture to help keep it maintainable. Finally, you'll handle your app's reactive data with global state management. Ready to take your front-end skills to the next level? See you in the first chapter! Learning Outcomes. By the end of this course, you will be able to:. Build a Vue.js application. Scale your application with Vue CLI. Create reusable components in Vue.js.

Manage the global state of an application with Vuex. To succeed in this course, you need prior knowledge of HTML, CSS, JavaScript (ES2015+), npm, basic terminal commands, and Git.

Project structure

You can acquire these skills by taking the following course and its prerequisites:. Put the client app in a separate project, outside from the ASP.NET Core project.

  • Create the client project based on the framework CLI installed on your computer. Currently, the front-end project must be published manually (not currently supported with the Publish tool).
  • For additional information, see https://github.com/MicrosoftDocs/visualstudio-docs/issues/7135. Visual Studio 2022 Preview 2 or later with the ASP.NET and web development workload installed. Go to the Visual Studio downloads page to install it for free.If you need to install the workload and already have Visual Studio, go to Tools > Get Tools and Features.., which opens the Visual Studio Installer.
  • Choose the ASP.NET and web development workload, then choose Modify. npm (https://www.npmjs.com/), which is included with Node.js.
  • Vue CLI (https://cli.vuejs.org/). In the New Project Dialog, select Create a new project. Search for Vue in the search bar at the top and then select Standalone JavaScript Vue Template or Standalone TypeScript Vue Template. Give your project and solution a name. When you get to the Additional information window, be sure to check the Add integration for Empty ASP.NET Web API Project option. This option adds files to your Vue template so that it can be hooked up later with the ASP.NET Core project. vue.config.json (modified). HelloWorld.vue (modified). package.json (modified). In Solution Explorer, right-click the solution name, hover over Add, and then select New Project.
  • In Solution Explorer, right-click the ASP.NET Core project and choose Properties. Go to the Debug menu and select Open debug launch profiles UI option. Clear the Launch browser option. Currently, launch.json must be located under the .vscode folder. Right-click the solution and select Set Startup Project. Change the startup project from Single startup project to Multiple startup projects. Select Start for each project’s action. Next, select the backend project and move it above the frontend, so that it starts up first. Before you start the project, make sure that the port numbers match. Go to the launchSettings.json file in your ASP.NET Core project (in the Properties folder). Get the port number from the applicationUrl property.

In the Debug menu, switch the profile using the Start button drop-down menu to the profile for your backend app.

.vue files (single file components)

Next, in the Solution properties, reset to multiple startup projects.

While some frameworks encourage you to separate your template, logic, and styling code into separate files, Vue takes the opposite approach. Using Single File Components, Vue lets you group your templates, corresponding script, and CSS all together in a single file ending in .vue. These files are processed by a JS build tool (such as Webpack), which means you can take advantage of build-time tooling in your project. This allows you to use tools like Babel, TypeScript, SCSS and more to create more sophisticated components.

As a bonus, projects created with the Vue CLI are configured to use .vue files with Webpack out of the box. In fact, if you look inside the src folder in the project we created with the CLI, you'll see your first .vue file: App.vue.

Let's explore this now.

App.vue

Open your App.vue file — you'll see that it has three parts: