New vuejs project
Here's a step-by-step guide to creating a new Vue.js project:
Option 1: Using Vue CLI
-
Install Vue CLI globally:
npm install -g @vue/cli
-
Create a new project:
vue create my-vue-app
Replace
my-vue-app
with your desired project name. -
Follow the prompts to choose the project template and configuration options.
Option 2: Using Vue CLI with a specific template
- Install Vue CLI globally:
npm install -g @vue/cli
- Create a new project with a specific template:
vue create my-vue-app --template webpack-simple
Replace
my-vue-app
with your desired project name andwebpack-simple
with the desired template (e.g.,webpack
,vue-router
, etc.).
Option 3: Using npm init and installing Vue.js manually
- Create a new directory for your project:
mkdir my-vue-app
- Initialize the project with npm:
cd my-vue-app npm init
- Install Vue.js and other dependencies:
npm install vue npm install vue-router npm install vuex
- Create a new file called
main.js
and add the following code:import Vue from 'vue' import App from './App.vue' import router from './router' import store from './store'
Vue.config.productionTip = false
new Vue({ router, store, render: h => h(App) }).$mount('#app')
5. Create a new file called `App.vue` and add the following code:
```vue
<template>
<div>
<h1>Welcome to my Vue.js app!</h1>
</div>
</template>
<script>
export default {
name: 'App'
}
</script>
- Create a new file called
router.js
and add the following code:import Vue from 'vue' import Router from 'vue-router' import App from './App.vue'
Vue.use(Router)
export default new Router({ routes: [ { path: '/', component: App } ] })
7. Create a new file called `store.js` and add the following code:
```javascript
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
count: 0
},
mutations: {
increment (state) {
state.count++
}
}
})
- Start the development server:
npm run serve
This will start the development server and you can access your app at
http://localhost:8080
.
That's it! You now have a basic Vue.js project set up.