Vue+Element switch组件的使用

<el-table-column label="商品状态" align="center">
          <template slot-scope="{row}">
            <el-switch
              v-model="row.goods_state"
              class="switch"
              :active-value="1"
              :inactive-value="0"
              active-text="上架"
              inactive-text="下架"
              @change="change($event,row)"
            />
          </template>
        </el-table-column>

参数说明:

widthswitch 的宽度(像素)
active-textswitch 打开时的文字描述
inactive-textswitch 关闭时的文字描述
active-value

switch 打开时的值

inactive-valueswitch 关闭时的值
active-colorswitch 打开时的背景色
inactive-colorswitch 关闭时的背景色

完整代码:

 <el-table-column label="商品状态" align="center">
          <template slot-scope="{row}">
            <el-switch
              v-model="row.goods_state"
              class="switch"
              :active-value="1"
              :inactive-value="0"
              @change="change($event,row)"
            />
          </template>
        </el-table-column>



<script>
 methods: {
    //状态切换
    change(data, row) {
      console.log(data);
      console.log(row);
      //此处可以请求后端接口更改商品状态
    },
  }
};

</script>

如何让文字在按钮中显示如以下这样

 

解决办法:加入以下css样式

/* switch按钮样式 */
.switch .el-switch__label {
  position: absolute;
  display: none;
  color: #fff !important;
}
/*打开时文字位置设置*/
.switch .el-switch__label--right {
  z-index: 1;
}
/* 调整打开时文字的显示位子 */
.switch .el-switch__label--right span{
  margin-right: 9px;
}
/*关闭时文字位置设置*/
.switch .el-switch__label--left {
  z-index: 1;
}
/* 调整关闭时文字的显示位子 */
.switch .el-switch__label--left span{
  margin-left: 9px;
}
/*显示文字*/
.switch .el-switch__label.is-active {
  display: block;
}
/* 调整按钮的宽度 */
.switch.el-switch .el-switch__core,
.el-switch .el-switch__label {
  width: 60px !important;
  margin: 0;
}

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,下面是基于 Vue.jsElement UI 组件库实现的柱状图示例: 1. 安装 Element UI 组件库并按需引入相应组件: ``` npm i element-ui -S ``` ```js // 在 main.js 中按需引入组件 import Vue from 'vue'; import { Button, Select, Option, Row, Col, Input, Form, FormItem, Loading, Message, MessageBox, Notification, Container, Header, Aside, Main, Menu, Submenu, MenuItem, MenuItemGroup, Breadcrumb, BreadcrumbItem, Card, Table, TableColumn, Pagination, Dialog, Dropdown, DropdownMenu, DropdownItem, Tabs, TabPane, Checkbox, CheckboxGroup, Radio, RadioGroup, Switch, DatePicker, TimePicker, Upload, Steps, Step, Carousel, CarouselItem, Tooltip, Popover, Alert, Tag, Badge, Progress, Tree, Cascader, Avatar, Divider, Image, Popconfirm, Slider, Transfer, ColorPicker, Scrollbar, Collapse, CollapseItem } from 'element-ui'; Vue.use(Button); Vue.use(Select); Vue.use(Option); Vue.use(Row); Vue.use(Col); Vue.use(Input); Vue.use(Form); Vue.use(FormItem); Vue.use(Loading.directive); Vue.prototype.$loading = Loading.service; Vue.prototype.$message = Message; Vue.prototype.$msgbox = MessageBox; Vue.prototype.$alert = MessageBox.alert; Vue.prototype.$confirm = MessageBox.confirm; Vue.prototype.$prompt = MessageBox.prompt; Vue.prototype.$notify = Notification; Vue.use(Container); Vue.use(Header); Vue.use(Aside); Vue.use(Main); Vue.use(Menu); Vue.use(Submenu); Vue.use(MenuItem); Vue.use(MenuItemGroup); Vue.use(Breadcrumb); Vue.use(BreadcrumbItem); Vue.use(Card); Vue.use(Table); Vue.use(TableColumn); Vue.use(Pagination); Vue.use(Dialog); Vue.use(Dropdown); Vue.use(DropdownMenu); Vue.use(DropdownItem); Vue.use(Tabs); Vue.use(TabPane); Vue.use(Checkbox); Vue.use(CheckboxGroup); Vue.use(Radio); Vue.use(RadioGroup); Vue.use(Switch); Vue.use(DatePicker); Vue.use(TimePicker); Vue.use(Upload); Vue.use(Steps); Vue.use(Step); Vue.use(Carousel); Vue.use(CarouselItem); Vue.use(Tooltip); Vue.use(Popover); Vue.use(Alert); Vue.use(Tag); Vue.use(Badge); Vue.use(Progress); Vue.use(Tree); Vue.use(Cascader); Vue.use(Avatar); Vue.use(Divider); Vue.use(Image); Vue.use(Popconfirm); Vue.use(Slider); Vue.use(Transfer); Vue.use(ColorPicker); Vue.use(Scrollbar); Vue.use(Collapse); Vue.use(CollapseItem); ``` 2. 在组件使用 echarts 绘制柱状图并绑定数据: ```html <template> <div class="chart-container"> <div ref="chart" class="chart"></div> </div> </template> <script> import echarts from 'echarts'; export default { name: 'BarChart', data() { return { chartData: [ { month: '一月', sales: 1000 }, { month: '二月', sales: 1200 }, { month: '三月', sales: 800 }, { month: '四月', sales: 1500 }, { month: '五月', sales: 1300 }, { month: '六月', sales: 1700 }, { month: '七月', sales: 900 } ] } }, mounted() { // 基于准备好的dom,初始化echarts实例 let myChart = echarts.init(this.$refs.chart); // 指定图表的配置项和数据 let option = { title: { text: '月度销售额', subtext: '单位:元' }, tooltip: {}, xAxis: { data: this.chartData.map(item => item.month), axisLabel: { interval: 0, // 强制显示所有刻度标签 rotate: 45, // 旋转角度 margin: 10 // 刻度标签与轴线之间的距离 } }, yAxis: {}, series: [{ name: '销售额', type: 'bar', data: this.chartData.map(item => item.sales), itemStyle: { // 柱形图圆角 barBorderRadius: 5 } }] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); } } </script> <style scoped> .chart-container { width: 100%; height: 400px; display: flex; justify-content: center; align-items: center; } .chart { width: 80%; height: 80%; } </style> ``` 以上就是基于 Vue.jsElement UI 组件库实现的柱状图示例。其中,echarts 是一个非常强大的数据可视化库,可以通过配置项和数据来绘制各种类型的图表。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值