(vue)下拉框联动选择后,自动复制到剪贴板然后Ctrl+V粘贴
<div class="selectOption">
<span class="demonstration">手动复制维度名称:</span>
<Select v-model="value" placeholder="请选择" id="select">
<Option
v-for="item in options"
:key="item.value"
:label="item.chinese"
:value="item.en"
>
</Option>
</Select>
<Select v-model="value2" placeholder="请选择" id="select">
<Option
v-for="item in arr"
:key="item.value"
:label="item.chinese"
:value="item.en"
>
</Option>
</Select>
</div>
data() {
return {
arr: [],
options: [],
value: "",
value2: "",
};
},
watch: {
value: {
deep: true,
// immediate: true,
handler(newVal, oldVal) {
this.value2 = "";
const input = document.createElement("input");
input.style.cssText = "opacity: 0;";
input.type = "text";
input.value = newVal; // 修改文本框的内容
document.body.appendChild(input);
input.select(); // 选中文本
document.execCommand("copy"); // 执行浏览器复制命令
this.$Message.success("复制成功");
let temp = this.options.filter((item) => item.en == newVal)[0]
.relation;
console.log(temp);
this.arr = temp;
},
},
value2: {
deep: true,
// immediate: true,
handler(newVal, oldVal) {
if (newVal) {
const input = document.createElement("input");
input.style.cssText = "opacity: 0;";
input.type = "text";
input.value = newVal; // 修改文本框的内容
document.body.appendChild(input);
input.select(); // 选中文本
document.execCommand("copy"); // 执行浏览器复制命令
this.$Message.success("复制成功");
}
},
},
},
methods:{
//获取options
findSchemaByParam({
graph: this.enName,
}).then((res) => {
this.options = res.data.data;
});
}
数据格式:
效果: