控制台报错Cannot read properties of undefined (reading ‘0‘)

this.options[0] ? this.options[0].label : null

<script>
export default {
    // props: ['title', 'selectShow', 'options'],
    // 改成这个形式
    props: {
        options: {
            type: Array,
            default: () => []
        },
        title: {
            type: String,
            default: ''
        },
        selectShow: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            sValue: ''
        }
    },
    mounted() {
        // console.log(this.options);
// 判断有数据赋值
        this.sValue = this.options[0] ? this.options[0].label : null
    },
    methods: {
        change(e) {
            console.log(e, 'e');
            this.$emit("sValue", this.sValue, this.options[0].label)
        }
    }
}
</script>

你可能感兴趣的:(vue2,javascript,前端,vue.js)