邓宏
3 years ago
6 changed files with 96 additions and 52 deletions
@ -1,54 +1,90 @@ |
|||
<script setup> |
|||
import { ref, useAttrs, useSlots, useCssVars, inject, defineExpose, onMounted } from 'vue' |
|||
|
|||
console.log(inject("store"),'---------------store--------') |
|||
console.log(useAttrs(),'-------useAttrs-------') |
|||
|
|||
console.log(useSlots(),'---------useSlots--') |
|||
defineProps({ |
|||
msg: String |
|||
}) |
|||
useCssVars(e=>{ |
|||
console.log(e,"-----------ctx----") |
|||
}) |
|||
const emit=defineEmits(['close']) |
|||
console.log(emit,'-------emit-----------') |
|||
const count = ref(0) |
|||
const color="#342e91" |
|||
defineExpose({ // 暴露数据,提供父元素使用 |
|||
count |
|||
}) |
|||
</script> |
|||
|
|||
<style lang='less' scoped> |
|||
a { |
|||
color: #42b983; |
|||
background: v-bind(color); |
|||
} |
|||
.demo{ |
|||
color:blue; |
|||
span{ |
|||
font-weight: bold; |
|||
text-decoration: initial; |
|||
font-size:40px; |
|||
} |
|||
} |
|||
</style> |
|||
<style lang="less" module="cssName"> |
|||
.demo{ |
|||
color:red; |
|||
span{ |
|||
font-weight: bold; |
|||
text-decoration: initial; |
|||
font-size:40px; |
|||
} |
|||
} |
|||
</style> |
|||
<template> |
|||
<h1 v-bind="$attrs">{{ msg }}</h1> |
|||
<slot/> |
|||
<slot name="demo"/> |
|||
<p> |
|||
<p v-my-directive> |
|||
Recommended IDE setup: |
|||
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a> |
|||
+ |
|||
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a> |
|||
</p> |
|||
|
|||
<p> |
|||
<!-- v-memo 类似于 v-one 数组内的值变换时会更新 --> |
|||
<p v-memo="[b]"> |
|||
{{count}} |
|||
<a href="https://vitejs.dev/guide/features.html" target="_blank"> |
|||
Vite Documentation |
|||
</a> |
|||
| |
|||
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Documentation</a> |
|||
</p> |
|||
|
|||
<div class="demo">1-<span>2</span></div> |
|||
<button type="button" @click="count++">count is: {{ count }}</button> |
|||
<p> |
|||
Edit |
|||
<p :class="cssName.demo"> |
|||
<span>Edit</span>{{foo}} |
|||
<code>components/HelloWorld.vue</code> to test hot module replacement. |
|||
</p> |
|||
</template> |
|||
<script setup> |
|||
import { ref, useAttrs, useSlots, useCssVars, inject, defineExpose } from 'vue' |
|||
|
|||
console.log(inject("store"),'---------------store--------') |
|||
console.log(useAttrs(),'-------useAttrs-------') |
|||
console.log(useSlots(),'---------useSlots--') |
|||
defineProps({ |
|||
msg: String |
|||
}) |
|||
useCssVars(e=>{ |
|||
console.log(e,"-----------ctx----") |
|||
}) |
|||
const emit=defineEmits(['close']) |
|||
console.log(emit,'-------emit-----------') |
|||
const count = ref(0) |
|||
const color="#342e91" |
|||
const b=ref('ddd') |
|||
window.b=b |
|||
defineExpose({ // 暴露数据,提供父元素使用 |
|||
count |
|||
}) |
|||
|
|||
<style lang='less' scoped> |
|||
a { |
|||
color: #42b983; |
|||
background: v-bind(color); |
|||
} |
|||
</style> |
|||
const vMyDirective={ |
|||
// 指令具有一组生命周期钩子: |
|||
// 在绑定元素的 attribute 或事件监听器被应用之前调用 |
|||
created(el, binding, vnode) {}, |
|||
// 在绑定元素的父组件挂载之前调用 |
|||
beforeMount() {}, |
|||
// 在绑定元素的父组件挂载之后调用 |
|||
mounted() {}, |
|||
// 在包含组件的 VNode 更新之前调用 |
|||
beforeUpdate() {}, |
|||
// 在包含组件的 VNode 及其子组件的 VNode 更新之后调用 |
|||
updated() {}, |
|||
// 在绑定元素的父组件卸载之前调用 |
|||
beforeUnmount() {}, |
|||
// 在绑定元素的父组件卸载之后调用 |
|||
unmounted() {} |
|||
} |
|||
</script> |
|||
|
Loading…
Reference in new issue