传递字符串参数
str += `<span class="devicesIcon" onclick=deviceClick('${repDevices[i].deviceIds}')>
<i class="icon iconfont"></i>
</span>`
传递对象参数: ```javascript // 1、先进行转义 let data = JSON.stringify(repDevices[i]).replace(/“/g, “"”);
//2、 定义 testClick 点击事件,并传递 对象参数
str += <span class="devicesIcon" onclick="testClick(${data})">
<i class="icon iconfont"></i>
</span>
// 3、 定义testClick函数 mounted() { window.testClick = (str) => { console.log(‘0000’, str) }; },
- 实例
```javascript
function createRspMarker(data) {
let repDevices = data.devices;
for (let i = 0; i < repDevices.length; i++) {
let data = JSON.stringify(repDevices[i]).replace(/"/g, """);
// 获取到设备的id
switch (repDevices[i].deviceName) {
case 'RSU':
str += ` <span class="devicesIcon" onclick="testClick(${data})">
<i class="icon iconfont"></i>
</span>`
break;
}
}
}
mounted() {
window.testClick = (str) => {
console.log('0000', str)
};
},