Vite项目管理工具,代替webpack
安装
npm install -g create-vite-app
创建
create-vite-app demo
安装依赖运行项目
cd demo
npm install
npm run dev
webpack项目管理工具
git clone '地址' demo
cd demo
npm install
npm run dev
Vue-cli项目管理工具
npm install -g @vue/cli
vue create demo
cd demo
vue add vue-next
npm run serve
script引入
<script src="http://unpkg.com/vue@next"></script>
项目结构
- new Vue 改写成 Vue.createApp
- el获取跟目录 改写成 mount()
- 注:使用了Vue3后对应2的写法 new Vue 将不再适用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="http://unpkg.com/vue@next"></script>
</head>
<body>
<div id="root"></div>
</body>
<script>
//局部组件
const Counter = {
mounted() {
console.log(this.$attrs)
},
template: `
<div :msg="$attrs.msg"></div>
<div v-bind="$attrs"></div>
<div :msg2="$attrs.msg"></div>
`
}
let app = Vue.createApp({
components: { 'Counter': Counter },
data() { return { content: 'hello' } },
template:
'<div>{{content}}</div><todo-item></todo-item><Counter msg="a" msg2="b"/>'
})
//全局组件
app.component('todo-item', {
template: `<div>hello</div>`
})
app.mount('#root')
</script>
</html>