• 传递字符串参数

      1. str += `<span class="devicesIcon" onclick=deviceClick('${repDevices[i].deviceIds}')>
      2. <i class="icon iconfont">&#xe652;</i>
      3. </span>`
    • 传递对象参数: ```javascript // 1、先进行转义 let data = JSON.stringify(repDevices[i]).replace(/“/g, “"”);

    //2、 定义 testClick 点击事件,并传递 对象参数 str += <span class="devicesIcon" onclick="testClick(${data})"> <i class="icon iconfont">&#xe656;</i> </span>

    // 3、 定义testClick函数 mounted() { window.testClick = (str) => { console.log(‘0000’, str) }; },

    1. - 实例
    2. ```javascript
    3. function createRspMarker(data) {
    4. let repDevices = data.devices;
    5. for (let i = 0; i < repDevices.length; i++) {
    6. let data = JSON.stringify(repDevices[i]).replace(/"/g, "&quot;");
    7. // 获取到设备的id
    8. switch (repDevices[i].deviceName) {
    9. case 'RSU':
    10. str += ` <span class="devicesIcon" onclick="testClick(${data})">
    11. <i class="icon iconfont">&#xe656;</i>
    12. </span>`
    13. break;
    14. }
    15. }
    16. }
    17. mounted() {
    18. window.testClick = (str) => {
    19. console.log('0000', str)
    20. };
    21. },