Will all the default values of vue components become invalid after they are introduced into prop?

I want to implement:

(:colorpropsp)

problems encountered:

getStyle()colorfont-size

Target:

1.stylegetStyle()colorfont-size()
2.colorcolorfont-sizegetStyle()()
3.colorfont-weight(font-size)()
4.font-weightfont-italic(:),()

here is a small example I wrote:

:)

<template>
    <div>
        <p :style="getStyle()">haha

</div> </template> <script> export default { name: "Test", props: { textStyle: Object }, methods: { getStyle() { return this.textStyle || { "color": "-sharp999", "font-size": "22px" } } } } </script>
Mar.13,2021

    getStyle() {
        return Object.assign({
            'color': '-sharp999',
            'font-size': '22px'
        },this.textStyle)
    }

I understand your problem is to merge the style attribute of the default setting with the externally passed attribute. If the two have the same attribute, the externally passed attribute will prevail, and if this attribute is not passed in externally, the default value will be used. For some properties that do not have a default value, they use the properties that are passed in externally.

The simpler way to

is to merge the two attributes directly with Object.assign . Also, I recommend that you use the computed calculation property instead of methods to define this, because the calculation attribute can calculate new values in real time based on external property changes.

<template>
    <div>
        <p :style="getStyle">haha

</div> </template> <script> export default { name: 'Test', props: { textStyle: Object }, computed: { getStyle() { const defaultStyle = { 'color': '-sharp999', 'font-size': '22px' } return Object.assign(defaultStyle, this.textStyle || {}) } } } </script>

what if it's a method

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37c63-2c0a1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37c63-2c0a1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?