📑博客主页:@丘比特惩罚陆
💖欢迎关注:点赞收藏⭐留言✒
💬系列专栏:web前端、嵌入式、笔记专栏
🎮 加入社区: 灌水乐园
🥇人生格言:选对方向,每走一步都是进步!
✒️欢迎大佬指正,一起学习!一起加油!👏 希望大家能小手一动,帮忙点个赞!
😁资源邮箱:2237814512@qq.com;微信:lss0901lili1130
目录


关于 props 其实是不推荐直接 props 后面啪的是一堆东西,而是对象的形式一个个详细的给,方便后面的维护。
- //props: [ " name', 'type', "list', 'isVisible'],
- props:{
- name: String,
- type:{
- validator: function(value){
- //这个值必须匹配下列字符串中的一个
- return [""success",""warning"."danger""].includes(value);
- },
- list:{
- type: Array,
- //对象或数组默认值必须从一个工厂函散获取
- default:()=>[]
- ),
- isVisible: {type: Boolean,default: false},
- onChange: {
- type: Function,default:()=>{}
- }
- },

答案:

在组件initProps方法的时候,会对props进行delineReactive操作,传入的第四个参数是自定义的sel的数,该函数会在触发props的set方法时执行,当props修改了,就会运行这里传入的第四个参数,然后进行判断,如果不Mroot根组件,并且不是更新子组件,那么说明更新的是props,所以会警告。
- if (process.env.NODE_EN !== ' production '){
- var hyphenatedKey = hyphenate(key);
- if (isReservedAttribute(hyphenatedKey) ||
- config.isReservedAttr(hyphenatedKey)){
- warn(
- ("\""+ hyphenatedKey +"\" is a reserved attribute and cannot be used as component prop."),
- vm
- );
- }
- defineReactives$$1( props,key,value,function (){
- if(!isRoot && !isUpdatingchildcomponent) {
- warn(
- "Avoid mutating a prop directly since the value will be " +"overwritten whenever the parent component re-renders." +
- "Instead, use a data or computed property based on the prop's " +"value.Prop being mutated:"" + key +"\"",
- vm
- );));

- name: {{ nane || "--" }}
- <input :value="name"" @change="handleChange"/>
- <br/>
- <br/>
- <div @click="handleDivclick">
- <button @click="handleClick">重置成功button>
- <button aclick.stop="handleClick">重置失败button>
- div>
-
- <script>
- export default {
- name:"EventDeno",
- props:{
- name: String,
- methods:{
- handleChange(e) {
- this.$emit("change".e.target.value);
- },
- handleDivClick() {
- this.$emit("change","");
- },
- handleclick(e){
- //都会失败
- //e.stopPropagation()
- :
- script>

现在其实都不区分插槽了,推荐使用下面的方式即每一段下面那种(↑)。
"slot" tab="插槽"> - <h2>2.6新语法h2>
- <SlotDemo>
- <p>default slotp>
- <template v-slot:title>
- <p>title slot1p>
- <p>title siot2p>
- template>
- <template v-slot:item="props">
- <p>item slot-scope {{ props }}p>
- template>
- SlotDemo>
- <br/>
- <h2>老语法h2>
- <SlotDemo>
- <p>default slotp>
- <p slot="title">title slot1p>
- <p slot="title">title slot2p>
- <p slot="item" slot-scope="props">item slot-scope {{ props }}p>
- SlotDeno>
- <div>
- <slot/>
- <slot namea"title" />
- <slot hame="item" v-bind="{ value: 'vue' } />
