uniapp 写一个多规格的产品发布页面比如小米手机 先新增型号和颜色然后型号8+25612+256颜色:黑色紫色那么就会有小米手机8+256黑色小米手机8+256黑紫色小米手机12+256黑色小米手机12+256紫色这样的代码
<template>
<view class="container">
<view class="form-item">
<view class="label">型号:</view>
<view class="radio-group">
<view class="radio-item" :class="{ checked: currentModel === '8+256' }" @tap="handleModelChange('8+256')">8+256</view>
<view class="radio-item" :class="{ checked: currentModel === '12+256' }" @tap="handleModelChange('12+256')">12+256</view>
</view>
</view>
<view class="form-item">
<view class="label">颜色:</view>
<view class="radio-group">
<view class="radio-item" :class="{ checked: currentColor === '黑色' }" @tap="handleColorChange('黑色')">黑色</view>
<view class="radio-item" :class="{ checked: currentColor === '紫色' }" @tap="handleColorChange('紫色')">紫色</view>
</view>
</view>
<view class="form-item">
<view class="label">产品名称:</view>
<input type="text" v-model="productName" placeholder="请输入产品名称" />
</view>
<view class="form-item">
<view class="label">产品价格:</view>
<input type="number" v-model="productPrice" placeholder="请输入产品价格" />
</view>
<view class="form-item">
<view class="label">产品库存:</view>
<input type="number" v-model="productStock" placeholder="请输入产品库存" />
</view>
<view class="form-item">
<view class="label">产品描述:</view>
<textarea v-model="productDescription" placeholder="请输入产品描述"></textarea>
</view>
<view class="form-item">
<button class="submit-btn" @tap="handleSubmit">发布</button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
currentModel: '8+256',
currentColor: '黑色',
productName: '',
productPrice: '',
productStock: '',
productDescription: '',
};
},
methods: {
handleModelChange(model) {
this.currentModel = model;
},
handleColorChange(color) {
this.currentColor = color;
},
handleSubmit() {
const productName = `小米手机${this.currentModel}${this.currentColor}`;
const productPrice = this.productPrice;
const productStock = this.productStock;
const productDescription = this.productDescription;
// 发布产品的逻辑
},
},
};
</script>
<style lang="scss">
.container {
padding: 20rpx;
.form-item {
margin-bottom: 20rpx;
display: flex;
align-items: center;
.label {
width: 120rpx;
font-size: 28rpx;
}
.radio-group {
display: flex;
.radio-item {
display: flex;
align-items: center;
justify-content: center;
width: 120rpx;
height: 60rpx;
border: 1rpx solid #ccc;
border-radius: 30rpx;
margin-right: 20rpx;
font-size: 24rpx;
&.checked {
background-color: #007aff;
color: #fff;
}
}
}
input,
textarea {
flex: 1;
font-size: 28rpx;
padding: 10rpx;
border: 1rpx solid #ccc;
border-radius: 10rpx;
}
input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type='number'] {
-moz-appearance: textfield;
}
}
.submit-btn {
width: 100%;
height: 80rpx;
background-color: #007aff;
color: #fff;
font-size: 32rpx;
border: none;
border-radius: 10rpx;
}
}
</style
原文地址: https://www.cveoy.top/t/topic/hirH 著作权归作者所有。请勿转载和采集!