Skip to content

SKU product multi specification selector

This component is a lightweight, powerful, and scalable product that emulates the JD algorithm. It can use SKUs with images and automatically generate corresponding component theme colors based on the configured theme colors. It can be directly used by simply passing in the SKU array in the specified format.

Platform compatibility

App(vue)App(nvue)H5小程序VUE2VUE3

rely

Before using the pre component, it is necessary to install the dependency crypto-js to generate encrypted attribute names.

shell
npm install crypto-js
npm install crypto-js

Basic Use

vue
<template>
	<view class="test" style="padding: 3rem 1.5rem;">
		<wu-sku v-model="skuShow" :data="skus" :themeColor="[226, 35, 26]"
			defaultCover="https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/default.jpeg"
			btnConfirmText="purchase" notSelectSku="Please select complete product information" @skuChange="skuChange" @confirm="skuConfirm"></wu-sku>
		<!-- Open SKU component -->
		<button @click="skuShow = true">Open SKU component</button>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive,
		inject,
		toRefs
	} from "vue";
	import {} from '@dcloudio/uni-app';

	let skuShow = ref(false);
	// sku list
	let skus = ref([{
			id: 1,
			price: 7000,
			stock: 30,
			sku_attrs: {
				'body color': 'Deep Sky Black',
				'capacity': '128G',
				'suit': 'Quick charging set'
			}
		},
		{
			id: 2,
			price: 8500,
			stock: 10,
			sku_attrs: {
				'body color': 'Dark Purple',
				'capacity': '256G',
				'suit': 'Quick charging set'
			}
		},
		{
			id: 3,
			price: 9500,
			stock: 0,
			sku_attrs: {
				'body color': 'Dark Purple',
				'capacity': '512G',
				'suit': 'AirPodssuit'
			}
		},
		{
			id: 4,
			price: 9200,
			stock: 60,
			sku_attrs: {
				'body color': 'silvery',
				'capacity': '512G',
				'suit': 'AirPodssuit'
			}
		},
		{
			id: 5,
			price: 9200,
			stock: 80,
			sku_attrs: {
				'body color': 'golden',
				'capacity': '512G',
				'suit': 'AirPods3suit'
			}
		}
	])

	// If a change event occurs in the SKU, select the complete SKU to return. Otherwise, the value of SKU is {}
	let skuChange = (sku) => {
		console.log(sku);
	}
	// skuConfirm
	let skuConfirm = (e) => {
		console.log(e);
	}
</script>
<template>
	<view class="test" style="padding: 3rem 1.5rem;">
		<wu-sku v-model="skuShow" :data="skus" :themeColor="[226, 35, 26]"
			defaultCover="https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/default.jpeg"
			btnConfirmText="purchase" notSelectSku="Please select complete product information" @skuChange="skuChange" @confirm="skuConfirm"></wu-sku>
		<!-- Open SKU component -->
		<button @click="skuShow = true">Open SKU component</button>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive,
		inject,
		toRefs
	} from "vue";
	import {} from '@dcloudio/uni-app';

	let skuShow = ref(false);
	// sku list
	let skus = ref([{
			id: 1,
			price: 7000,
			stock: 30,
			sku_attrs: {
				'body color': 'Deep Sky Black',
				'capacity': '128G',
				'suit': 'Quick charging set'
			}
		},
		{
			id: 2,
			price: 8500,
			stock: 10,
			sku_attrs: {
				'body color': 'Dark Purple',
				'capacity': '256G',
				'suit': 'Quick charging set'
			}
		},
		{
			id: 3,
			price: 9500,
			stock: 0,
			sku_attrs: {
				'body color': 'Dark Purple',
				'capacity': '512G',
				'suit': 'AirPodssuit'
			}
		},
		{
			id: 4,
			price: 9200,
			stock: 60,
			sku_attrs: {
				'body color': 'silvery',
				'capacity': '512G',
				'suit': 'AirPodssuit'
			}
		},
		{
			id: 5,
			price: 9200,
			stock: 80,
			sku_attrs: {
				'body color': 'golden',
				'capacity': '512G',
				'suit': 'AirPods3suit'
			}
		}
	])

	// If a change event occurs in the SKU, select the complete SKU to return. Otherwise, the value of SKU is {}
	let skuChange = (sku) => {
		console.log(sku);
	}
	// skuConfirm
	let skuConfirm = (e) => {
		console.log(e);
	}
</script>
vue
<template>
	<view class="test" style="padding: 3rem 1.5rem;">
		<wu-sku 
			v-model="skuShow" 
			:data="skus" 
			:themeColor="[226, 35, 26]"
			defaultCover="https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/default.jpeg"
			btnConfirmText="purchase" notSelectSku="Please select complete product information" 
			@skuChange="skuChange" 
			@confirm="skuConfirm"
		></wu-sku>
		<!-- Open SKU component -->
		<button @click="skuShow = true">Open SKU component</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// Show components or not
				skuShow: false,
				// sku list
				skus: [{
						id: 1,
						price: 7000,
						stock: 30,
						sku_attrs: {
							'body color': 'Deep Sky Black',
							'capacity': '128G',
							'suit': 'Quick charging set'
						}
					},
					{
						id: 2,
						price: 8500,
						stock: 10,
						sku_attrs: {
							'body color': 'Dark Purple',
							'capacity': '256G',
							'suit': 'Quick charging set'
						}
					},
					{
						id: 3,
						price: 9500,
						stock: 0,
						sku_attrs: {
							'body color': 'Dark Purple',
							'capacity': '512G',
							'suit': 'AirPodssuit'
						}
					},
					{
						id: 4,
						price: 9200,
						stock: 60,
						sku_attrs: {
							'body color': 'silvery',
							'capacity': '512G',
							'suit': 'AirPodssuit'
						}
					},
					{
						id: 5,
						price: 9200,
						stock: 80,
						sku_attrs: {
							'body color': 'golden',
							'capacity': '512G',
							'suit': 'AirPods3suit'
						}
					}
				]
			}
		},
		methods: {
			// If a change event occurs in the SKU, select the complete SKU to return. Otherwise, the value of SKU is {}
			skuChange(sku) {
				console.log(sku);
			},
			// skuConfirm
			skuConfirm(e) {
				console.log(e);
			}
		}
	}
</script>
<template>
	<view class="test" style="padding: 3rem 1.5rem;">
		<wu-sku 
			v-model="skuShow" 
			:data="skus" 
			:themeColor="[226, 35, 26]"
			defaultCover="https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/default.jpeg"
			btnConfirmText="purchase" notSelectSku="Please select complete product information" 
			@skuChange="skuChange" 
			@confirm="skuConfirm"
		></wu-sku>
		<!-- Open SKU component -->
		<button @click="skuShow = true">Open SKU component</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// Show components or not
				skuShow: false,
				// sku list
				skus: [{
						id: 1,
						price: 7000,
						stock: 30,
						sku_attrs: {
							'body color': 'Deep Sky Black',
							'capacity': '128G',
							'suit': 'Quick charging set'
						}
					},
					{
						id: 2,
						price: 8500,
						stock: 10,
						sku_attrs: {
							'body color': 'Dark Purple',
							'capacity': '256G',
							'suit': 'Quick charging set'
						}
					},
					{
						id: 3,
						price: 9500,
						stock: 0,
						sku_attrs: {
							'body color': 'Dark Purple',
							'capacity': '512G',
							'suit': 'AirPodssuit'
						}
					},
					{
						id: 4,
						price: 9200,
						stock: 60,
						sku_attrs: {
							'body color': 'silvery',
							'capacity': '512G',
							'suit': 'AirPodssuit'
						}
					},
					{
						id: 5,
						price: 9200,
						stock: 80,
						sku_attrs: {
							'body color': 'golden',
							'capacity': '512G',
							'suit': 'AirPods3suit'
						}
					}
				]
			}
		},
		methods: {
			// If a change event occurs in the SKU, select the complete SKU to return. Otherwise, the value of SKU is {}
			skuChange(sku) {
				console.log(sku);
			},
			// skuConfirm
			skuConfirm(e) {
				console.log(e);
			}
		}
	}
</script>

Individual logo settings (effective when not using image SKU)

Each set of sku attributes can have their own logo attribute set. The logo attribute will be displayed after selecting complete sku, and the defaultCover attribute of the component will be displayed when not selecting complete sku

js
[
    ...
    {
        id: 5,
        price: 9200,
        logo: 'Image Path',
        stock: 80,
        sku_attrs: {
            'body color': 'golden',
            'capacity': '512G',
        }
    }
    ...
]
[
    ...
    {
        id: 5,
        price: 9200,
        logo: 'Image Path',
        stock: 80,
        sku_attrs: {
            'body color': 'golden',
            'capacity': '512G',
        }
    }
    ...
]

SKU with images

If you want a sku attribute to have an image display, simply change the original attribute name: attribute value to attribute name: {name: attribute name, img:'image link'} on the sku attribute of the image you want to display. For example, when we want the attribute of body color to have an image display.

js
// The following code can be directly copied and used
[
    {
        id: 1,
        price: 7000,
        stock: 30,
        sku_attrs: {
            'body color': {
                name: 'Deep Sky Black',
                img: 'https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/heise.jpeg',
            },
            'capacity': '128G',
            'suit': 'Quick charging set'
        }
    },
    {
        id: 2,
        price: 8500,
        stock: 10,
        sku_attrs: {
            'body color': {
                name: 'Dark Purple',
                img: 'https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/anyezi.jpeg',
            },
            'capacity': '256G',
            'suit': 'Quick charging set'
        }
    },
    {
        id: 3,
        price: 9500,
        stock: 0,
        sku_attrs: {
            'body color': {
                name: 'Dark Purple',
                img: 'https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/anyezi.jpeg',
            },
            'capacity': '512G',
            'suit': 'AirPodssuit'
        }
    },
    {
        id: 4,
        price: 9200,
        stock: 60,
        sku_attrs: {
            'body color': {
                name: 'silvery',
                img: 'https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/baise.jpeg',
            },
            'capacity': '512G',
            'suit': 'AirPodssuit'
        }
    },
    {
        id: 5,
        price: 9200,
        stock: 80,
        sku_attrs: {
            'body color': {
                name: 'golden',
                img: 'https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/jinse.jpeg',
            },
            'capacity': '512G',
            'suit': 'AirPods3suit'
        }
    }
]
// The following code can be directly copied and used
[
    {
        id: 1,
        price: 7000,
        stock: 30,
        sku_attrs: {
            'body color': {
                name: 'Deep Sky Black',
                img: 'https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/heise.jpeg',
            },
            'capacity': '128G',
            'suit': 'Quick charging set'
        }
    },
    {
        id: 2,
        price: 8500,
        stock: 10,
        sku_attrs: {
            'body color': {
                name: 'Dark Purple',
                img: 'https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/anyezi.jpeg',
            },
            'capacity': '256G',
            'suit': 'Quick charging set'
        }
    },
    {
        id: 3,
        price: 9500,
        stock: 0,
        sku_attrs: {
            'body color': {
                name: 'Dark Purple',
                img: 'https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/anyezi.jpeg',
            },
            'capacity': '512G',
            'suit': 'AirPodssuit'
        }
    },
    {
        id: 4,
        price: 9200,
        stock: 60,
        sku_attrs: {
            'body color': {
                name: 'silvery',
                img: 'https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/baise.jpeg',
            },
            'capacity': '512G',
            'suit': 'AirPodssuit'
        }
    },
    {
        id: 5,
        price: 9200,
        stock: 80,
        sku_attrs: {
            'body color': {
                name: 'golden',
                img: 'https://mp-16389c52-85e7-413f-b566-3da08e2fe054.cdn.bspapp.com/img/sku-test/jinse.jpeg',
            },
            'capacity': '512G',
            'suit': 'AirPods3suit'
        }
    }
]
js
[
    {
        id: 1,
        price: 7000,
        stock: 30,
        sku_attrs: {
            'body color': 'Deep Sky Black',
            'capacity': '128G',
            'suit': 'Quick charging set'
        }
    },
    {
        id: 2,
        price: 8500,
        stock: 10,
        sku_attrs: {
            'body color': 'Dark Purple',
            'capacity': '256G',
            'suit': 'Quick charging set'
        }
    },
    {
        id: 3,
        price: 9500,
        stock: 0,
        sku_attrs: {
            'body color': 'Dark Purple',
            'capacity': '512G',
            'suit': 'AirPodssuit'
        }
    },
    {
        id: 4,
        price: 9200,
        stock: 60,
        sku_attrs: {
            'body color': 'silvery',
            'capacity': '512G',
            'suit': 'AirPodssuit'
        }
    },
    {
        id: 5,
        price: 9200,
        stock: 80,
        sku_attrs: {
            'body color': 'golden',
            'capacity': '512G',
            'suit': 'AirPods3suit'
        }
    }
]
[
    {
        id: 1,
        price: 7000,
        stock: 30,
        sku_attrs: {
            'body color': 'Deep Sky Black',
            'capacity': '128G',
            'suit': 'Quick charging set'
        }
    },
    {
        id: 2,
        price: 8500,
        stock: 10,
        sku_attrs: {
            'body color': 'Dark Purple',
            'capacity': '256G',
            'suit': 'Quick charging set'
        }
    },
    {
        id: 3,
        price: 9500,
        stock: 0,
        sku_attrs: {
            'body color': 'Dark Purple',
            'capacity': '512G',
            'suit': 'AirPodssuit'
        }
    },
    {
        id: 4,
        price: 9200,
        stock: 60,
        sku_attrs: {
            'body color': 'silvery',
            'capacity': '512G',
            'suit': 'AirPodssuit'
        }
    },
    {
        id: 5,
        price: 9200,
        stock: 80,
        sku_attrs: {
            'body color': 'golden',
            'capacity': '512G',
            'suit': 'AirPods3suit'
        }
    }
]

Specify default selected SKU

SelectSkuIndex is used to specify the SKU index to be selected by default.

vue
<wu-sku
    v-model="skuShow"
    :data="skus"
    defaultCover="http://rn8zfvrr0.hn-bkt.clouddn.com/e40744e32a2930f945e67da79a35f270.jpg?e=1672666137&token=0qmhoqQQZ4ggfGZOevcNXE4wYe_IZD3Y5xm8ZZ5Y:bxn-lcJPnFNY22kGWwh5MRgdGwM="
    btnConfirmText="purchase"
    notSelectSku="Please select complete product information"
    :isShowStock="false"
    :selectSkuIndex="3"
    @skuChange="skuChange"
    @confirm="skuConfirm"
></wu-sku>
<wu-sku
    v-model="skuShow"
    :data="skus"
    defaultCover="http://rn8zfvrr0.hn-bkt.clouddn.com/e40744e32a2930f945e67da79a35f270.jpg?e=1672666137&token=0qmhoqQQZ4ggfGZOevcNXE4wYe_IZD3Y5xm8ZZ5Y:bxn-lcJPnFNY22kGWwh5MRgdGwM="
    btnConfirmText="purchase"
    notSelectSku="Please select complete product information"
    :isShowStock="false"
    :selectSkuIndex="3"
    @skuChange="skuChange"
    @confirm="skuConfirm"
></wu-sku>

Is irrelevant SKU disabled

Are the remaining SKU attributes that are not related to the currently selected SKU attribute disabled.

vue
<wu-sku
    v-model="skuShow"
    :data="skus"
    defaultCover="http://rn8zfvrr0.hn-bkt.clouddn.com/e40744e32a2930f945e67da79a35f270.jpg?e=1672666137&token=0qmhoqQQZ4ggfGZOevcNXE4wYe_IZD3Y5xm8ZZ5Y:bxn-lcJPnFNY22kGWwh5MRgdGwM="
    btnConfirmText="购买"
    skuUnrelatedDisabled
    :skuDisabledStyle="{}"
    notSelectSku="请选择完整的商品信息"
    :isShowStock="false"
    :selectSkuIndex="3"
    @skuChange="skuChange"
    @confirm="skuConfirm"
></wu-sku>
<wu-sku
    v-model="skuShow"
    :data="skus"
    defaultCover="http://rn8zfvrr0.hn-bkt.clouddn.com/e40744e32a2930f945e67da79a35f270.jpg?e=1672666137&token=0qmhoqQQZ4ggfGZOevcNXE4wYe_IZD3Y5xm8ZZ5Y:bxn-lcJPnFNY22kGWwh5MRgdGwM="
    btnConfirmText="购买"
    skuUnrelatedDisabled
    :skuDisabledStyle="{}"
    notSelectSku="请选择完整的商品信息"
    :isShowStock="false"
    :selectSkuIndex="3"
    @skuChange="skuChange"
    @confirm="skuConfirm"
></wu-sku>

If you are not satisfied with the sku disabled style, you can modify the style by setting skuDisabledStyle, and the object's form is sufficient.

SKU Props

Attribute NameillustratetypesDefault valueOptional values
dataSource data (SKU list)Array[]-
value/modelValue/v-modelShow SKU componentsBooleanfalsetrue/false
isMaskCloseCan I click on the mask layer to close itBooleanfalsetrue/false
isSelectMinPriceSkuIs the SKU with the lowest price selected by defaultBooleantruetrue/false
selectSkuIndexDefault selected SKU subscriptNumber/Stringnull-
defaultCoverDefault cover image, used to display when a complete SKU is not selectedString""-
defaultNumDefault purchase quantityNumber/String1-
themeColorTheme colors require passing in an array with a length of 3, corresponding to the values of the three colors of rgb, for example: [84, 164, 255]Array[84, 164, 255]-
btnConfirmTextConfirm button textString"确认"-
skuUnrelatedDisabledAre the remaining SKU attributes that are not related to the currently selected SKU attribute disabled.Booleanfalsetrue/false
skuDisabledStyleSKU disable stylesObject{}-
notStockTextOut of stock text, effective when notStockDisabled is falseString"库存不足"-
notSelectSkuText prompt when a complete SKU is not selectedString"请选择完整的sku属性"-
showStockNumDisplay inventory quantityBooleantruetrue/false

SKU Events

nameillustrateCallback Arguments
confirmEvent triggered when clicking the confirm buttone = { sku, skuText , num }。Corresponds to the selected SKU value, SKU attribute name array, and the quantity in the input box.
skuChangeThe event that sets off when the SKU changes. If a complete SKU is selected, it will be returned. Otherwise, it will be returned{}e = {}
numChangeTrigger event when the quantity in the input box changese = num, Return the number of input boxes
closeClose SKU component trigger event-
openOpen the SKU component to trigger an event-

SKU Methods

nameillustrate
resetNumReset purchase quantity