element.md 8.3 KB
Newer Older
D
DCloud_LXH 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
## Element

<!-- CUSTOMTYPEJSON.Element.description -->

<!-- CUSTOMTYPEJSON.Element.extends -->

<!-- CUSTOMTYPEJSON.Element.param -->

### 方法
<!-- CUSTOMTYPEJSON.Element.methods.getNodeId.name -->

<!-- CUSTOMTYPEJSON.Element.methods.getNodeId.description -->

<!-- CUSTOMTYPEJSON.Element.methods.getNodeId.param -->

<!-- CUSTOMTYPEJSON.Element.methods.getNodeId.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.getNodeId.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.getNodeId.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.appendChild.name -->

<!-- CUSTOMTYPEJSON.Element.methods.appendChild.description -->

<!-- CUSTOMTYPEJSON.Element.methods.appendChild.param -->

<!-- CUSTOMTYPEJSON.Element.methods.appendChild.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.appendChild.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.appendChild.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.insertBefore.name -->

<!-- CUSTOMTYPEJSON.Element.methods.insertBefore.description -->

<!-- CUSTOMTYPEJSON.Element.methods.insertBefore.param -->

<!-- CUSTOMTYPEJSON.Element.methods.insertBefore.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.insertBefore.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.insertBefore.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.setAttribute.name -->

<!-- CUSTOMTYPEJSON.Element.methods.setAttribute.description -->

50 51
**注意**
setAttribute从HBuilderX 3.93起,调整为只能保存string类型属性值,需要保存其它类型数据请使用dataset属性。
DCloud-yyl's avatar
DCloud-yyl 已提交
52

D
DCloud_LXH 已提交
53 54 55 56 57 58 59 60 61 62 63 64
<!-- CUSTOMTYPEJSON.Element.methods.setAttribute.param -->

<!-- CUSTOMTYPEJSON.Element.methods.setAttribute.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.setAttribute.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.setAttribute.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.getAttribute.name -->

<!-- CUSTOMTYPEJSON.Element.methods.getAttribute.description -->

65
**注意**
W
x  
wanganxp 已提交
66
getAttribute返回值从HBuilderX 3.93起,调整为string类型,不要使用此方法获取非string类型的属性值。如有非string需求,请使用对象的点操作符直接访问dateset属性,不通过getAttribute方法。
DCloud-yyl's avatar
DCloud-yyl 已提交
67

D
DCloud_LXH 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
<!-- CUSTOMTYPEJSON.Element.methods.getAttribute.param -->

<!-- CUSTOMTYPEJSON.Element.methods.getAttribute.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.getAttribute.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.getAttribute.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.hasAttribute.name -->

<!-- CUSTOMTYPEJSON.Element.methods.hasAttribute.description -->

<!-- CUSTOMTYPEJSON.Element.methods.hasAttribute.param -->

<!-- CUSTOMTYPEJSON.Element.methods.hasAttribute.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.hasAttribute.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.hasAttribute.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.removeAttribute.name -->

<!-- CUSTOMTYPEJSON.Element.methods.removeAttribute.description -->

<!-- CUSTOMTYPEJSON.Element.methods.removeAttribute.param -->

<!-- CUSTOMTYPEJSON.Element.methods.removeAttribute.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.removeAttribute.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.removeAttribute.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.getBoundingClientRect.name -->

<!-- CUSTOMTYPEJSON.Element.methods.getBoundingClientRect.description -->

<!-- CUSTOMTYPEJSON.Element.methods.getBoundingClientRect.param -->

<!-- CUSTOMTYPEJSON.Element.methods.getBoundingClientRect.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.getBoundingClientRect.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.getBoundingClientRect.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.getDrawableContext.name -->

<!-- CUSTOMTYPEJSON.Element.methods.getDrawableContext.description -->

<!-- CUSTOMTYPEJSON.Element.methods.getDrawableContext.param -->

<!-- CUSTOMTYPEJSON.Element.methods.getDrawableContext.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.getDrawableContext.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.getDrawableContext.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.addEventListener.name -->

<!-- CUSTOMTYPEJSON.Element.methods.addEventListener.description -->

<!-- CUSTOMTYPEJSON.Element.methods.addEventListener.param -->

<!-- CUSTOMTYPEJSON.Element.methods.addEventListener.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.addEventListener.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.addEventListener.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.removeEventListener.name -->

<!-- CUSTOMTYPEJSON.Element.methods.removeEventListener.description -->

<!-- CUSTOMTYPEJSON.Element.methods.removeEventListener.param -->

<!-- CUSTOMTYPEJSON.Element.methods.removeEventListener.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.removeEventListener.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.removeEventListener.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.removeChild.name -->

<!-- CUSTOMTYPEJSON.Element.methods.removeChild.description -->

<!-- CUSTOMTYPEJSON.Element.methods.removeChild.param -->

<!-- CUSTOMTYPEJSON.Element.methods.removeChild.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.removeChild.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.removeChild.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.remove.name -->

<!-- CUSTOMTYPEJSON.Element.methods.remove.description -->

<!-- CUSTOMTYPEJSON.Element.methods.remove.param -->

<!-- CUSTOMTYPEJSON.Element.methods.remove.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.remove.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.remove.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.dispatchEvent.name -->

<!-- CUSTOMTYPEJSON.Element.methods.dispatchEvent.description -->

<!-- CUSTOMTYPEJSON.Element.methods.dispatchEvent.param -->

<!-- CUSTOMTYPEJSON.Element.methods.dispatchEvent.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.dispatchEvent.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.dispatchEvent.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.scrollTo.name -->

<!-- CUSTOMTYPEJSON.Element.methods.scrollTo.description -->

<!-- CUSTOMTYPEJSON.Element.methods.scrollTo.param -->

<!-- CUSTOMTYPEJSON.Element.methods.scrollTo.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.scrollTo.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.scrollTo.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.scrollBy.name -->

<!-- CUSTOMTYPEJSON.Element.methods.scrollBy.description -->

<!-- CUSTOMTYPEJSON.Element.methods.scrollBy.param -->

<!-- CUSTOMTYPEJSON.Element.methods.scrollBy.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.scrollBy.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.scrollBy.tutorial -->

D
DCloud_LXH 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
<!-- CUSTOMTYPEJSON.Element.methods.focus.name -->

<!-- CUSTOMTYPEJSON.Element.methods.focus.description -->

<!-- CUSTOMTYPEJSON.Element.methods.focus.param -->

<!-- CUSTOMTYPEJSON.Element.methods.focus.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.focus.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.focus.tutorial -->

<!-- CUSTOMTYPEJSON.Element.methods.blur.name -->

<!-- CUSTOMTYPEJSON.Element.methods.blur.description -->

<!-- CUSTOMTYPEJSON.Element.methods.blur.param -->

<!-- CUSTOMTYPEJSON.Element.methods.blur.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.blur.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.blur.tutorial -->
231 232 233 234 235 236 237 238 239 240 241 242

<!-- CUSTOMTYPEJSON.Element.methods.takeSnapshot.name -->

<!-- CUSTOMTYPEJSON.Element.methods.takeSnapshot.description -->

<!-- CUSTOMTYPEJSON.Element.methods.takeSnapshot.param -->

<!-- CUSTOMTYPEJSON.Element.methods.takeSnapshot.returnValue -->

<!-- CUSTOMTYPEJSON.Element.methods.takeSnapshot.compatibility -->

<!-- CUSTOMTYPEJSON.Element.methods.takeSnapshot.tutorial -->
W
x  
wanganxp 已提交
243

杜庆泉's avatar
杜庆泉 已提交
244

DCloud_Heavensoft's avatar
DCloud_Heavensoft 已提交
245
```ts
杜庆泉's avatar
杜庆泉 已提交
246 247
// 找到需要截图节点
const view = uni.getElementById('snapshot-content')!
杜庆泉's avatar
杜庆泉 已提交
248
// 进行截图
杜庆泉's avatar
杜庆泉 已提交
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
view.takeSnapshot({
    success: function (res) {
        // 打印截图文件临时路径
        console.log(res.tempFilePath)
        uni.showToast({
            title: '截图成功,路径:' + res.tempFilePath,
            icon: "none"
        })
    },
    fail: function (res) {
        console.log(res)
        uni.showToast({
            icon: 'error',
            title: '截图失败'
        })
    }
})
```

完整示例代码参考[hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha/pages/API/element-takesnapshot/element-takesnapshot.uvue)