In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to use defineProps and defineEmits in vue3.0 grammatical sugar". In daily operation, I believe many people have doubts about how to use defineProps and defineEmits in vue3.0 grammatical sugar. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about how to use defineProps and defineEmits in vue3.0 grammatical sugar. Next, please follow the editor to study!
DefineProps, defineEmits1 and defineProps in grammatical sugar
Get component pass value
☆ ★ import {defineProps, defineEmits, computed, ref} from "vue" / / defineProps () / / adopt ts proprietary declaration There is a default value interface Props {value: number theme: string} const props = withDefaults (defineProps (), {value: 0, theme: 'blue'}) / / non-ts proprietary declaration / / let props = defineProps ({/ / value: Number,// theme: {/ / type: String / / default: 'blue'//} / /}) let width = ref (props.value) function mouseOver (I: number) {width.value = I} function mouseOut () {width.value = props.value} const fontWidth = computed (() = > `width: ${width.value} em `) const themeObj: {[key: string]: string} = {'black':' # 000, 'white':' # f80, 'red':' # f5222d, 'orange':' # 8f0, 'yellow':' # 80f, 'green':' # 0f6, 'blue':' # 08f,} const fontstyle = computed (() = > `color: ${themeObj [props.theme]};`). Rate {position: relative Display: inline-block;}. Rate > span.hollow {position: absolute; display: inline-block; top: 0; left: 0; width: 0; overflow: hidden;} 2, defineEmits
The child component passes to the parent component event
☆ ★ import {defineProps, defineEmits, computed, ref} from "vue" * * ditto code omit / / non-ts declaration / / let emits = defineEmits (['update-rate']) / / function onRate (num) {/ / emits (' update-rate', num) / /} / / adopt ts proprietary declaration Let emits = defineEmits () function onRate (num: number) {emits ('update-rate', num)} / / description of vue grammar sugar in the code above
Some tags can be omitted in the Vue2.X version.
Grammatical sugar refers to adding a method to achieve the same effect without affecting the function so as to facilitate program development.
Vue.js v-bind v-on instructions provide grammatical sugar, which can also be called abbreviations, such as v-bind can omit v-bind.
Just write a colon ":":
V-bind can be omitted as xx:xx, such as
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.