error `slot` attributes are deprecated vue/no-deprecated-slot-attribute

旧的代码如下:

<template slot="title">{{ item.title }}</template>

{{ item.title }} 是一个模板标签,它在模板中插入了一个元素(slot),并指定了元素的名称为 “title”。这个标签在模板中显示为一个空白元素,可以通过设置其 data 属性来提供内容。

但是会报错:


解决方法:

在Vue.js中,slot是一种分发内容的机制,用于在子组件中插入内容。slot的使用中有一种旧的语法,即在template标签上使用slot属性,这种语法已被弃用。
解决方法是使用新的语法,在插入位置使用slot标签,如下所示:

<template>  <div>    <slot name="title"></slot>  </div></template>

在调用处使用v-slot指令,如下所示:

<my-component>  <template v-slot:title>    {{ item.title }}  </template></my-component>

这样就可以避免slot attributes are deprecated vue/no-deprecated-slot-attribute的警告。

                        
原文链接:https://blog.csdn.net/qq_30503389/article/details/130557761

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值