Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
1937 มุมมอง

Dear all,

I have a JS class as below:

export class Product extends Component {

    static components = { PTAL };

    static template = "sale_product_configurator.product";

    static props = {

        id: { type: [Number, {value: false}], optional: true },

        product_tmpl_id: Number,

        display_name: String,

        description_sale: [Boolean, String], // backend sends 'false' when there is no description

        price: Number,

}

Now I want to inherit and add new items for props, but I do not know how to do.

Help me please.

Thank.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

To inherit and add new items to the props in your Product component class, you can extend the class and then define the additional props in the new class. Here’s how you can do it:

``` import { Product } from '@sale_product_configurator/js/product/product';


export class ExtendedProduct extends Product {

    static props = {

        ...Product.props,

        new_prop1: String, // Add new properties here

        new_prop2: Number,

    };

}


Hope it helps

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
4
ก.พ. 25
2264
2
พ.ย. 24
3086
3
ต.ค. 23
14650
2
ก.พ. 23
2330
1
ธ.ค. 22
1371