Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

vue2项目创建

作者:残情弑天   发布日期:2025-06-10   浏览:68

// 使用 Vue CLI 创建 Vue 2 项目

// 首先确保你已经安装了 Vue CLI,如果没有安装,可以通过以下命令进行全局安装:
// npm install -g @vue/cli

// 然后通过以下命令创建一个新的 Vue 2 项目:
// vue create my-project-name

// 在创建过程中,选择手动配置项目,并选择 Vue 2 作为默认版本。

// 以下是创建 Vue 2 项目的示例代码和解释:

// 1. 初始化项目结构
// 这一步会生成一个基础的 Vue 2 项目结构,包含 src 目录、public 目录等。
// 其中 src 目录是主要的开发目录,包含组件、路由、状态管理等。

// 2. 安装依赖
// 进入项目目录并安装依赖:
// cd my-project-name
// npm install

// 3. 启动开发服务器
// 使用以下命令启动开发服务器:
// npm run serve

// 4. 示例代码:src/main.js
import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false

new Vue({
  render: h => h(App),
}).$mount('#app')

// 5. 示例代码:src/App.vue
<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
  </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>

// 6. 示例代码:src/components/HelloWorld.vue
<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1 {
  color: #42b983;
}
</style>

上一篇:vue request

下一篇:vue component组件

大家都在看

vue.config.js configu

node.js vue

vue查看版本

vue等待几秒

vue3 setup computed

vue screenfull

vue json.stringify

vue 遍历list

typescript vue

vue 复选框

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站