Escolar Documentos
Profissional Documentos
Cultura Documentos
io/s/k1oxxp284r
Go in some dir Vue2019
D:\Vue2019\> vue create my-app
Tip: If you already have vue-cli installed, make sure you are on the latest version by typing vue
--version into your cli.
Now that you have an instantiated project, you can add the Vuetify package using the cli.
Once Vuetify has been installed, navigate to your application's main entry point. In most cases
this will be index.js or main.js. In this file you will import Vuetify and tell Vue to use it.
Vue.use(Vuetify)
First example
o See on Codepen
Second example: the Vue CLI default app
o Use the Vue CLI locally
o Use CodeSandbox
o The files structure
o index.html
o src/main.js
o src/App.vue
o src/components/HelloWorld.vue
o Run the app
If you’ve never created a Vue.js application, I am going to guide you through the task of creating
one, and understanding how it works.
First example
<html>
<body>
<div id="example">
<p>{{ hello }}</p>
</div>
<script src="https://unpkg.com/vue"></script>
<script>
new Vue({
el: '#example',
data: { hello: 'Hello World!' }
})
</script>
</body>
</html>
and you open it in the browser. That’s your first Vue app! The page should show a “Hello
World!” message.
I put the script tags at the end of the body so that they are executed in order after the DOM is
loaded.
What this code does is, we instantiate a new Vue app, linked to the #example element as its
template (it’s defined using a CSS selector usually, but you can also pass in an HTMLElement).
Then, it associates that template to the data object. That is a special object that hosts the data we
want Vue to render.
In the template, the special {{ }} tag indicates that’s some part of the template that’s dynamic,
and its content should be looked up in the Vue app data.
See on Codepen
Codepen is a little different from using a plain HTML file, and you need to configure it to point
to the Vue library location in the Pen settings:
Let’s level up the game a little bit. The next app we’re going to build is already done, and it’s the
Vue CLI default application.
What is the Vue CLI? It’s a command line utility that helps to speed up development by
scaffolding an application skeleton for you, with a sample app in place.
The first is to install the Vue CLI on your computer, and run the command
CodeSandbox is a cool code editor that allows you build apps in the cloud, which allows you to
use any npm package and also easily integrate with Zeit Now for an easy deployment and
GitHub to manage versioning.
That link I put above opens the Vue CLI default application.
Whether you chose to use the Vue CLI locally, or through CodeSandbox, let’s inspect that Vue
app in detail.
The files structure
Beside package.json, which contains the configuration, these are the files contained in the
initial project structure:
index.html
src/App.vue
src/main.js
src/assets/logo.png
src/components/HelloWorld.vue
index.html
In the body it includes just one simple element: <div id="app"></div>. This is the element the
Vue application will use to attach to the DOM.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>CodeSandbox Vue</title>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
src/main.js
We first import the Vue library and the App component from App.vue.
We set productionTip to false, just to avoid Vue to output a “you’re in development mode” tip in
the console.
Next, we create the Vue instance, by assigning it to the DOM element identified by #app, which
we defined in index.html, and we tell it to use the App component.
/* eslint-disable no-new */
new Vue({
el: '#app',
components: { App },
template: '<App/>'
})
src/App.vue
App.vue is a Single File Component. It contains 3 chunks of code: HTML, CSS and JavaScript.
This might seem weird at first, but Single File Components are a great way to create self-
contained components that have all they need in a single file.
We have the markup, the JavaScript that is going to interact with it, and style that’s applied to it,
which can be scoped, or not. In this case, it’s not scoped, and it’s just outputting that CSS which
is applied like regular CSS to the page.
This component is going to be referenced in our component. It’s a dependency. We are going to
output this code:
<div id="app">
<img width="25%" src="./assets/logo.png">
<HelloWorld/>
</div>
from this component, which you see references the HelloWorld component. Vue will
automatically insert that component inside this placeholder.
<template>
<div id="app">
<img width="25%" src="./assets/logo.png">
<HelloWorld/>
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld'
export default {
name: 'App',
components: {
HelloWorld
}
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
src/components/HelloWorld.vue
Remember above we talked about CSS in App.vue, which was not scoped? The HelloWorld
component has scoped CSS.
You can easily determine it by looking at the style tag. If it has the scoped attribute, then it’s
scoped: <style scoped>
This means that the generated CSS will be targeting the component uniquely, via a class that’s
applied by Vue transparently. You don’t need to worry about this, and you know the CSS won’t
leak to other parts of the page.
The message the component outputs is stored in the data property of the Vue instance, and
outputted in the template as {{ msg }}.
Anything that’s stored in data is reachable directly in the template via its own name. We didn’t
need to say data.msg, just msg.
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<h2>Essential Links</h2>
<ul>
<li>
<a
href="https://vuejs.org"
target="_blank"
>
Core Docs
</a>
</li>
<li>
<a
href="https://forum.vuejs.org"
target="_blank"
>
Forum
</a>
</li>
<li>
<a
href="https://chat.vuejs.org"
target="_blank"
>
Community Chat
</a>
</li>
<li>
<a
href="https://twitter.com/vuejs"
target="_blank"
>
Twitter
</a>
</li>
<br>
<li>
<a
href="http://vuejs-templates.github.io/webpack/"
target="_blank"
>
Docs for This Template
</a>
</li>
</ul>
<h2>Ecosystem</h2>
<ul>
<li>
<a
href="http://router.vuejs.org/"
target="_blank"
>
vue-router
</a>
</li>
<li>
<a
href="http://vuex.vuejs.org/"
target="_blank"
>
vuex
</a>
</li>
<li>
<a
href="http://vue-loader.vuejs.org/"
target="_blank"
>
vue-loader
</a>
</li>
<li>
<a
href="https://github.com/vuejs/awesome-vue"
target="_blank"
>
awesome-vue
</a>
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
data() {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1,
h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
Run the app
CodeSandbox has a cool preview functionality. You can run the app and edit anything in the
source to have it immediately reflected in the preview.
Installing and Starting Node
https://medium.com/@anaida07/mevn-stack-application-part-1-3a27b61dcae0
The acronym “MEVN” stands for “MongoDB Express.js VueJS Node.js”. In this post, I am
going to show how to create a basic MEVN (MongoDB/Express/VueJS/Node.js) Stack
application.
This tutorial is based onMongoDB v3.0.5, ExpressJS v4.15.4, VueJS v2.4.2, Node.js v8.5.0.
This guide will be focused on generating a skeleton for MEVN full stack application. We will
cover the Mongo part in the next tutorial. The github repo for this tutorial can be found here.
mkdir posts
cd posts
Now, we want to set up our client VueJS for the frontend. We will be using vue-cli to build up
the template.
(This command will ask you certain questions like project name, author, description, using
eslint, using test, etc. You can just hit enter for every question.)
Now, we have a folder named client in our application. As we can see, now we need to run npm
install inside the client folder to install all the dependencies listed in client/package.json
file. So, let’s go ahead and do it.
cd client
npm install
npm run dev
Running npm run dev will open up the http://localhost:8080/#/in the browser which renders the
default VueJS template.
Now that we have set up the frontend framework, let’s move ahead on creating the backend with
express . Let’s create a server folder in the root directory which is going to hold all the server
code.
mkdir server
cd server
We want to initialize this server project with npm which we can do with npm init -f which will
create a package.json file inside the server directory.
What this package.json file is missing is it doesn’t have a start command. So let’s do that
first so that we can run the server with npm start command. The package.json file should
look like this:
Now, let’s go ahead and create src folder inside this directory and create a file called app.js.
console.log('Hello World');
npm start
If everything went well, we should be able to see the printed out Hello World in the terminal.
https://coursetro.com/courses/23/Vue-Tutorial-in-2018---Learn-Vue.js-by-Example
Vue.js is a JavaScript Framework that competes with Angular and React. It's growing in
popularity in 2018, and it's a must-learn for the aspiring front-end developer.
In this course, we're going to learn how to use Vue to create a real project. In doing so, you're
going to learn all about the fundamentals of this great framework.
While learning all about this, you will build a simple app that allows you to add skills in a list-
style app.
This Vue Tutorial is really a crash course into learning one of the most popular frontend JS
frameworks today. It's just right for beginners who want to get up and running quickly, without
being bogged down by excessive powerpoint slides and theory.
Requirements
So, if you're ready to start learning Vue.js 2 today, let's get started!
Course Curriculum
Written Lesson: How to Install Vue 2 - Through CDN, NPM and the Vue CLI
Written Lesson: Vue Forms Tutorial - Capturing and Validating User Input
Written Lesson: Vue Animation Tutorial - Learn how to use Vue's Animation System
Note: This tutorial is a part of our free course: Vue Tutorial in 2018 - Learn Vue.js by Example
In 2018, Vue.js is growing in popularity and if you've landed on this page, chances are -- you
want to start learning how to use this powerful JavaScript Framework.
I'm going to show you exactly how to get up and running with Vue.js 2 in this tutorial. There are
several methods from which you can install Vue, and we're going to cover them all.
There's a quick and easy method that involves simply referencing a CDN, a method that uses the
Node Package Manager (NPM) to integrate it into existing projects, and then the Vue CLI.
The easiest and quickest way of installing Vue is by directly including Vue via a CDN (Content
Delivery Network) in a <script> tag. This means that instead of Vue residing on your own
server, it will be delivered from a separate server. Technically, you aren't installing Vue in this
scenario, as you're simply creating a reference of Vue.
If you're interested in using this method, open up your command line or console and create a new
folder:
Open up your code editor and create an index.html file with the following content:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Vue CDN</title>
</head>
<body>
<script
src="https://cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.js"></script>
</body>
</html>
If you view this index.html file in a browser and view the console (ctrl-shift-i in Chrome), you
will see the message:
This means that Vue has been integrated and you're ready to rock. To prove this, we can create a
very simple Vue app.
Go back to the index.html and update it to match the following within the body tags:
<body>
<div id="app">
{{ message }}
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
})
</script>
</body>
Refresh the browser and you will see Hello Vue!, which means Vue is working.
Throughout this course and our project, however, we are not going to use this method. Feel free
to delete the /vue-cdn folder you just created.
NPM (Node Package Manager) is used to install packages. You can use it to install Vue within
either a new or existing project.
You will need to ensure you have Node.js installed along with access to NPM. To check, open
up your console and type:
> node -v
> npm -v
Both of these commands should provide you with version numbers. If they go unrecognized,
visit Nodejs.org and download the appropriate installer based on your operating system. Install it
through the default options and reload your console. You can now re-issue the same commands
and they will work.
First, we have to create a new project folder:
In order to save our project dependencies based on what we install with NPM, we need to create
a package.json file.
This will create a new package.json file and enter the defaults -y for the prompts.
At this point, you could create an index.html file with the same exact contents as the CDN
example above, except change the <script .. src to node_modules/vue/dist/vue.js, and it will work
just the same.
Typically, however, you would use something like Webpack or Gulp as a more robust
development environment.
Because our project is not going to be set up in this fashion, we're going to use the Vue CLI
method as the actual method that we use to install Vue.
The Vue CLI (Command Line Interface) is a quick, easy and robust way to get started with a
brand new Vue project.
Also, you will need to make sure Node is up to date. By the way: You can also use Yarn to install
Vue.
To keep things simple, we'll leave it at the default option and hit enter.
After it's finished installing, you can hop into the directory and then serve the Vue app:
> cd vue-proj
> yarn serve