vue3搭建
  JQHgqRpfEpBc 2023年11月19日 20 0

一、Vue 3介绍:

// 创建一个 Vue 实例
const app = Vue.createApp({
  data() {
    return {
      message: 'Hello Vue!'
    }
  }
})

app.mount('#app')

二、安装Vue 3:

npm install -g @vue/cli
# 或者
yarn global add @vue/cli

vue create my-project

三、开始开发:

<template>
  <div class="hello">
    {{ msg }}
  </div>
</template>

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

<style scoped>
h1, h2 {
  font-weight: normal;
}
</style>

四、Composition API:

import { ref } from 'vue'

export default {
  setup(props, context) {
    const count = ref(0)
  
    function increment () {
      count.value++
    }
  
    return { count, increment }
  }
}

五、路由:

import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home.vue'

const routes = [
  { path: '/', component: Home },
  // ...
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

六、状态管理:

import { createStore } from 'vuex'

export default createStore({
  state: {
    count: 0
  },
  mutations: {
    increment (state) {
      state.count++
    }
  },
  actions: {
    increment ({ commit }) {
      commit('increment')
    }
  }
})


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月19日 0

暂无评论

推荐阅读
  gYl4rku9YpWY   2024年05月17日   57   0   0 Vue
  JZjRRktyDDvK   2024年05月02日   81   0   0 Vue
  VlNAKfyhjjp9   2024年04月30日   78   0   0 Vue
  JNTrZmaOQEcq   2024年04月30日   54   0   0 Vue
  onf2Mh1AWJAW   2024年05月17日   60   0   0 Vue
  3A8RnFxQCDqM   2024年05月17日   59   0   0 Vue
JQHgqRpfEpBc