Vue.js 目录结构

npm 安装项目, 在 IDE中打开该目录,结构

目录/文件说明
build项目构建(webpack)相关代码
config配置目录,包括端口号等。 初学可以使用默认的。
node_modulesnpm 加载的项目依赖模块
src

这里是 要开发的目录,基本上要做的事情都在这个目录里。里面包含了几个目录及文件:

  • assets: 放置一些图片,如logo等。

  • components: 目录里面放了个组件文件,可以不用。

  • App.vue: 项目入口文件, 也可以直接将组件写这里,而不使用 components 目录。

  • main.js: 项目的核心文件。

static静态资源目录,如图片、字体等。
test初始测试目录,可删除
.xxxx文件这些是一些配置文件,包括语法配置,git配置等。
index.html首页入口文件,你可以添加一些 meta 信息或统计代码啥的。
package.json项目配置文件。
README.md项目的说明文档,markdown 格式

打开 APP.vue 文件,代码(解释在注释中):

src/APP.vue

<template>
<div id="app"><img src="./assets/logo.png"><hello></hello></div>
</template>
<script>// 导入组件
import Hello from './components/Hello'
export default {
name: 'app',
components: { Hello }
}
</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>
修改下初始化的项目,将 Hello.vue 修改为以下代码 src/components/Hello.vue
<template>
<
div class="hello"><h1>{{ msg }}</h1></div>
</
template>
<
script>
export default {
name: 'hello',
data () {
return { msg: '欢迎来到小鸟启蒙!' }
}
}
</script>
打开页面 http://localhost:8080/
显示效果