element 简易二维码生成

首先安装二维码模块

cnpm install qrcodejs2 --save

页面用

<div id="qrCode" ref="myQrCode"></div>

或者直接

<div id="qrCode" ></div>

 

设置具体参数有三种方式:

1.mounted中直接设置:

mounted() {

 new QRCode(this.$refs.myQrCode, {

 text: "https://www.baidu.com",

 width: 150,// 宽度

 height: 150,

 colorDark: "#333333", //二维码颜色

 colorLight: "#ffffff", //二维码背景色

 correctLevel: QRCode.CorrectLevel.L //容错率,L/M/H

 });

}

2.created里用this.$nextTick的回掉函数

created() {

 this.$nextTick(function() {

 new QRCode(this.$refs.myQrCode, {

  text: "https://www.baidu.com",

  width: 150,

  height: 150,

  colorDark: "#333333", //二维码颜色

  colorLight: "#ffffff", //二维码背景色

  correctLevel: QRCode.CorrectLevel.L //容错率,L/M/H

 });

 });

}

3.方法里设置,比如点击个按钮弹出来之类的

mounted: function () {

 this.$nextTick(function () {

 this.bindQRCode();

 })

},

methods: {

 clickQRCode() {

 new QRCode(this.$refs.myQrCode, {

  text: 'https://www.baidu.com',

  width: 150,

  height: 150,

  colorDark: "#333333", //二维码颜色

  colorLight: "#ffffff", //二维码背景色

  correctLevel: QRCode.CorrectLevel.L//容错率,L/M/H

 })

 }

}

 

生成二维码js必须在 this.$nextTick(function(){调用})或setTimeout(() => { 调用 }, 100),是为了确保二维码容器DOM已经存在

为了防止重复生成二维码document.getElementById("qrcode").innerHTML = "";在方法中置空

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue Element 表单动态生成是指通过VueElement UI库来实现表单的动态生成和渲染的功能。 在Vue中,可以使用v-for指令结合数组或对象来循环渲染表单元素,实现动态生成表单。 首先,需要定义一个数据对象来存储表单项的信息,例如表单项的类型、名称、默认值等。然后,在Vue的模板中使用v-for指令来遍历数据对象,根据表单项的类型不同,使用Element UI提供的不同的表单组件来渲染对应的表单元素。 示例代码如下: 在Vue的data中定义表单项的信息: data() { return { formItems: [ { type: 'input', label: '姓名', value: '' }, { type: 'select', label: '性别', value: '', options: ['男', '女'] }, { type: 'datepicker', label: '生日', value: '' } ] } } 在Vue的模板中使用v-for遍历表单项并渲染表单元素: <el-form ref="form" :model="form" label-width="80px"> <el-form-item v-for="item in formItems" :label="item.label" :key="item.label"> <template v-if="item.type === 'input'"> <el-input v-model="form[item.label]" placeholder="请输入姓名"></el-input> </template> <template v-if="item.type === 'select'"> <el-select v-model="form[item.label]" placeholder="请选择性别"> <el-option v-for="option in item.options" :key="option" :label="option" :value="option"></el-option> </el-select> </template> <template v-if="item.type === 'datepicker'"> <el-date-picker v-model="form[item.label]" type="date" placeholder="请选择生日"></el-date-picker> </template> </el-form-item> </el-form> 这样,通过循环遍历表单项数据对象,动态生成对应的表单元素,实现了表单的动态生成和渲染。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值