开始创建
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
lintOnSave:false//关闭语法检查
})
// vue2中,借助render,传入h,h就是外壳app
new Vue({
render: (h) => h(App)
}).$mount('#app')
import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App)
app.mount("#app")
app.unmount("#app")
VUE3组件中的模板结构可以没有根标签
VUE2中没有会报错
<template>
<!-- VUE3组件中的模板结构可以没有根标签 -->
<h1>我是{{name}},我{{age}}</h1>
<button @click="sayword">点我</button>
</template>
<script>
export default {
name: 'App',
setup(){
let name ="乞力马扎罗"
let age =18
function sayword(){
console.log(`你好${name},我${age}`)
}
return{
name,
age,
sayword
}
},
}
</script>
<style>
</style>
<template>
<!-- VUE3组件中的模板结构可以没有根标签 -->
<h1>我是{{name}},我{{age}}</h1>
<button @click="sayword">点我</button>
</template>
<script>
import {h} from "vue"
export default {
name: 'App',
setup(){
let name ="乞力马扎罗"
let age =18
function sayword(){
console.log(`你好${name},我${age}`)
}
return ()=>h('button','看我强制替换你')
},
}
</script>
<style>
</style>
import {ref} from "vue"
setup() {
let name =ref("乞力马扎罗");
let age = ref(18);
function sayword() {
console.log(name,age);
}
return {
name,
age,
sayword,
};
},
setup() {
let name =ref("乞力马扎罗");
let age = ref(18);
function sayword() {
name.value="罗曼蒂克"
age.value=42
console.log(name,age);
}
return {
name,
age,
sayword,
};
},
<template>
<h1>我是{{ name }},我{{ age }}</h1>
<h1>我是{{ job.type }},我{{ job.salus}}</h1>
<button @click="sayword">点我更新信息</button>
</template>
<script>
import {ref} from "vue"
export default {
name: "App",
setup() {
let name =ref("乞力马扎罗");
let age = ref(18);
let job = ref({
type:"前端",
salus:"30k"
});
function sayword() {
name.value="罗曼蒂克"
age.value=42
job.value.type="后端"
console.log(name,age);
}
return {
name,
age,
job,
sayword,
};
},
};
</script>
<style>
</style>
<script>
import {reactive, ref} from "vue"
export default {
name: "App",
setup() {
let name =ref("乞力马扎罗");
let age = ref(18);
let job = reactive({
type:"前端",
salus:"30k"
});
function sayword() {
name.value="罗曼蒂克"
age.value=42
job.type="后端"
}
return {
name,
age,
job,
sayword,
};
},
};
</script>
<template>
<!-- VUE3组件中的模板结构可以没有根标签 -->
<h1>我是{{ name }},我{{ age }}</h1>
<h1>我是{{ job.type }},我{{ job.salus}}</h1>
<h1>我是{{ list[0] }}</h1>
<button @click="sayword">点我更新信息</button>
</template>
<script>
import {reactive, ref} from "vue"
export default {
name: "App",
setup() {
let name =ref("乞力马扎罗");
let age = ref(18);
let job = reactive({
type:"前端",
salus:"30k"
});
let list = reactive([1,2,3]);
function sayword() {
name.value="罗曼蒂克"
age.value=42
list[0]=4
job.type="后端"
}
return {
name,
age,
job,
list,
sayword,
};
},
};
</script>
<style>
</style>
<template>
<h1>我是{{ person.name }},我{{ person.age }}</h1>
<h1>我是{{ person.job.type }},我{{ person.job.salus }}</h1>
<h1>我是{{ person.list[0] }}</h1>
<button @click="sayword">点我更新信息</button>
</template>
<script>
import { reactive, ref } from "vue";
export default {
name: "App",
setup() {
let person = reactive({
name: "乞力马扎罗",
age: 18,
job: {
type: "前端",
salus: "30k",
},
list: [9],
});
function sayword() {
console.log(person)
person.name='罗曼蒂克'
person.list[0]='罗曼蒂克'
}
return {
person,
sayword,
};
},
};
</script>
<style>
</style>
从定义的角度
从原理角度:
从使用的角度