欢迎来到 Vue.js 中文快速入门教程!这里将帮助你快速了解并开始使用 Vue.js。

安装 Vue.js

首先,你需要安装 Vue.js。你可以通过以下命令来全局安装 Vue.js:

npm install -g @vue/cli

安装完成后,你可以使用 Vue CLI 创建一个新的 Vue.js 项目:

vue create my-vue-app

项目结构

创建项目后,你将得到一个基本的项目结构:

my-vue-app/
├── node_modules/
├── public/
│   └── index.html
├── src/
│   ├── assets/
│   ├── components/
│   ├── App.vue
│   ├── main.js
│   └── router/
├── .babelrc
├── .gitignore
├── package.json
└── package-lock.json

快速开始

创建组件

src/components 目录下创建一个新的 Vue 组件 HelloWorld.vue

<template>
  <div>
    <h1>Hello, Vue.js!</h1>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld'
}
</script>

<style scoped>
h1 {
  color: #42b983;
}
</style>

使用组件

src/App.vue 中引入并使用 HelloWorld 组件:

<template>
  <div id="app">
    <HelloWorld/>
  </div>
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'

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>

运行项目

在终端中运行以下命令来启动你的 Vue.js 项目:

npm run serve

打开浏览器,访问 http://localhost:8080/,你应该能看到 "Hello, Vue.js!" 的文字。

更多资源

想要了解更多关于 Vue.js 的内容,可以访问我们的 Vue.js 中文社区

[

Vue.js Logo
]