创建一个 vue.js 项目的步骤:安装先决条件: node.js (v16.x+)、vue cli(全局安装)。创建项目: 使用 vue create 命令,导航到目标目录。安装依赖: vue cli 自动安装依赖。运行项目: 在项目目录中,使用 npm run serve 命令。
手把手教你创建一个 Vue.js 项目
准备工作:
npm install -g @vue/cli
创建项目:
vue create
安装依赖:
立即学习“前端免费学习笔记(深入)”;
运行项目:
npm run serve
项目结构:
代码示例:
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')
<template><div>
<h1>{{ message }}</h1>
<button>Say Hello</button>
</div>
</template><script>
export default {
data() {
return {
message: 'Hello Vue!'
}
},
methods: {
sayHello() {
this.message = 'Hello, I am Vue!'
}
}
}
</script>
注意: