el-tooltip组件中content使用Vue-i18n报错TypeError: Cannot read property ‘$t‘ of null

一般我们组件内使用动态绑定时会这样写$t('manage.add'),当然也可以写this.$t('manage.add')

<el-input
	:placeholder="$t('manage.add')"
	v-model="input">
</el-input>
<el-input
	:placeholder="this.$t('manage.add')"
	v-model="input">
</el-input>

但是当我们使用el-tooltip组件时,使用this.$t('manage.edit')

<el-tooltip :content="this.$t('manage.edit')" placement="bottom">
	<el-button type="primary" icon="el-icon-edit" circle></el-button>
</el-tooltip>

就会报如下错误
在这里插入图片描述
这时我们需要把代码改为$t(‘manage.edit’)就可以了,如下

<el-tooltip :content="$t('manage.edit')" placement="bottom">
	<el-button type="primary" icon="el-icon-edit" circle></el-button>
</el-tooltip>

当我们使用i18n时,template里可以这样写

{
    
    {
    
    $t('manage.add')}}

script里可以这样写

this.$t('manage.add')

组件动态绑定可以这样写

$t('manage.add')或this.$t('manage.add')

然而部分组件则只能直接使用

$t('manage.add')

这就是造成错误的原因

猜你喜欢

转载自blog.csdn.net/qq_42783654/article/details/108419418
今日推荐