prop中如何获取vue data中的数据 中英文方案

答案:获取不到

解决办法

在vue文件重新导入相应的方法,再在props里面调用即可

下面是实例,因为页面需要做中英文翻译,正常的中英文如果在template里面中,是这样获取

<div :label="$t('message.configuration_border_line')" prop="borderWidth" v-if="isShowLine">{{$t('message.configuration_border_line')}}</div>

但是因为title值是一个变量,是从父组件传入的,然后用 $t('message.configuration_border_line' 一直获取不到,是因为props中读取不到vue实例的数据,解决如下

<template>
    <collapse-item  :title="title" :isShow="isShow"></collapse-item>
</template>
<script>
import i18n from '@common/langs/i18n'
import common from '@frameworks/assets/js/Common'
export default {
    name: 'BorderPrm',
    props:{
        title: {
            type: String,
            //default:'外观',
            default: common.getI18n(i18n.t('message.configuration_common_appearance'))
        }
    }
};
</script>

vue  中英文参照文章   https://www.cnblogs.com/1234wu/p/11093947.html

原文地址:https://www.cnblogs.com/pengfei25/p/14452841.html