默写,默写很重要,看10编不如默写一遍
<scirpt>
export default {
mounted(){
},
data(){
return {
a:[],
b:{},
c:"a"
}
},methods:[
a(){
this.c=this.c+"aa";
console.log(this.c);
}
]
</script>
组合式
<script setup>
import {ref } from 'vue'
const a=ref([]]
const b=ref({})
const c=ref("a")
function a(){
c.value=c.value+"aa";
}
</script>
一些 bind 笔记本
<script>
import {ref,onMounted } from 'vue'
const x=ref("xxx")
const options1=ref([])
const selects=ref([])
const checks=ref([])
const options=ref([
{
"title":"你好",
"value":"a"
}, {
"title":"你好1",
"value":"b"
}, {
"title":"你好2",
"value":"c"
}
])
onMounted(()=>{})
</script>
<template>
<input v-model="x"/>
{{x}}
<p>
current check: {{checks}}
current options: {{options}}
current options1: {{options1}}
{{selects}}
</p>
<input type="checkbox" id="a" value="a1" v-model="checks"/>
<select v-model="options1">
<option disabled dvalue="">please choose</option>
<option>a</option>
<option>b</option>
<option>c</option>
</select>
<select v-model="selects">
<option disabled value="">please choose default</option>
<option v-for="option in options" :value="option.value">
{{option.value}}</option>
</select>
</template>
更多对比
组合式
<script setup >
import {ref,onMounted} from 'vue'
onMounted(()=> {
pElementRef.value.textContent = 'moun11111ted!'
})
const a=ref("define a")
const pElementRef=ref(null)
</script>
<template>
{{a}}
<p ref="pElementRef">hello</p>
</template>
选项式
<script>
export default {
mounted() {
this.$refs.pElementRef.textContent = 'mounted!'
},data(){
return {
a:"xx"
}
}
}
</script>
<template>
{{a}}
<p ref="pElementRef">hello</p>
</template>
引用其他组件
这一次 组件式要少写一些代码
import ChildComp from './ChildComp.vue'
export default {
components: {
ChildComp
}
}
<template>
<ChildComp />
</template>
<script setup>
import ChildComp from './ChildComp.vue'
</script>
<template>
<ChildComp />
</template>
网友评论