关于报错"Templates should only be responsible for mapping the state to the UI"的原因整理

1.vue中实例挂载的元素节点名称不明确导致的

下面还原下过程:

①在index.html中引入头部信息top.html

②top.html引入top.js

**top.html,其最外层div的id取名为top(加入id是为了vue进行挂载)

**top.js,通过"#top"进行挂载

结果页面会报错,其报错信息如下(精简过):

[Vue warn]: Error compiling template:

<div id="top"><script type="text/javascript" src="./page-js/top.js"></script>
<div id="top">
	<div class="header">
	.........
</div>
</div>

- Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.

(found in <Root>)

最后发现原因,在index.html中也定义了id="top",导致了这个问题

所以,解决方式就是要么重命名index.html中id="top",要么重名vue挂载点id名称

Failed to compile. C:/Users/wang/Desktop/speedragon/page_index/car-sector/car-sector.vue?vue&type=template&id=ea66c920& (./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader??ref--17-0!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-app-loader/filter-modules-template.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-app-loader/page-meta.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib??vue-loader-options!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-scoped-loader!C:/Users/wang/Desktop/speedragon/page_index/car-sector/car-sector.vue?vue&type=template&id=ea66c920&) Module Error (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js): (Emitted value instead of an instance of Error) Errors compiling template: Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed. 231| </div> 232| 233| <script> | ^^^^^^^^ 234| document.addEventListener('DOMContentLoaded', function() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 235| // 移动端筛选面板切换 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 236| const mobileToggle = document.getElementById('mobileToggle'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 237| const filterContainer = document.getElementById('filterContainer'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 238| | ^^^^^^^^^^^^^^ 239| if (mobileToggle && filterContainer) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 240| mobileToggle.addEventListener('click', function() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 241| filterContainer.classList.toggle('active'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 242| mobileToggle.innerHTML = filterContainer.classList.contains('active') ? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 243| '<i class="fas fa-times"></i> 隐藏筛选条件' : | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 244| '<i class="fas fa-filter"></i> 显示筛选条件'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 245| }); | ^^^^^^^^^^^^^^^^^^^^^ 246| } | ^^^^^^^^^^^^^^^ 247| | ^^^^^^^^^^^^^^ 248| // 品牌选择效果 | ^^^^^^^^^^^^^^^^^^^^^^^ 249| const brandItems = document.querySelectorAll('.brand-item'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 250| brandItems.forEach(item => { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 251| item.addEventListener('click', function() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 252| this.classList.toggle('selected'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 253| if (this.classList.contains('selected')) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 254| this.style.backgroundColor = '#3498db'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 255| this.style.color = 'white'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 256| } else { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 257| this.style.backgroundColor = '#f0f7ff'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 258| this.style.color = '#333'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 259| } | ^^^^^^^^^^^^^^^^^^^^^^^ 260| }); | ^^^^^^^^^^^^^^^^^^^^^ 261| }); | ^^^^^^^^^^^^^^^^^ 262| | ^^^^^^^^^^^^^^ 263| // 范围选项选择效果 | ^^^^^^^^^^^^^^^^^^^^^^^^^ 264| const rangeOptions = document.querySelectorAll('.range-option'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 265| rangeOptions.forEach(option => { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 266| option.addEventListener('click', function() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 267| // 移除同一组中其他选项的选中状态 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 268| const groupName = this.querySelector('input').getAttribute('name'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 269| document.querySelectorAll(`input[name="${groupName}"]`).forEach(input => { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 270| input.parentElement.classList.remove('selected'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 271| }); | ^^^^^^^^^^^^^^^^^^^^^^^^^ 272| | ^^^^^^^^^^^^^^^^^^^^^^ 273| // 添加当前选项的选中状态 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 274| this.classList.add('selected'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 275| this.style.borderColor = '#3498db'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 276| this.style.backgroundColor = '#e1f0fa'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 277| }); | ^^^^^^^^^^^^^^^^^^^^^ 278| }); | ^^^^^^^^^^^^^^^^^ 279| | ^^^^^^^^^^^^^^ 280| // 应用筛选按钮 | ^^^^^^^^^^^^^^^^^^^^^^^ 281| const applyBtn = document.querySelector('.action-btn'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 282| if (applyBtn) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 283| applyBtn.addEventListener('click', function() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 284| alert('筛选条件已应用!页面将显示符合条件的结果'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 285| }); | ^^^^^^^^^^^^^^^^^^^^^ 286| } | ^^^^^^^^^^^^^^^ 287| }); | ^^^^^^^^^^^^^ 288| </script> | ^^^^^^^^^^^^^^^ 289| | 290| <style scoped> | ^^^^^^^^^^^^^^ 291| .content{ | ^^^^^^^^^^ 292| background-color: #f5f5f5; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 293| } | ^^ 294| .header { | ^^^^^^^^^^ 295| display: flex; | ^^^^^^^^^^^^^^^^^^^ 296| padding: 10rpx 5rpx; | ^^^^^^^^^^^^^^^^^^^^^^ 297| background-color: #fff; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 298| justify-content: center; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 299| align-items: center; | ^^^^^^^^^^^^^^^^^^^^^^^^^ 300| } | ^^ 301| | ^ 302| .logo { | ^^^^^^^^ 303| height: 80rpx; | ^^^^^^^^^^^^^^^^ 304| width: 300rpx; | ^^^^^^^^^^^^^^^^ 305| } | ^^ 306| | ^ 307| .search-bar { | ^^^^^^^^^^^^^^ 308| width: 80%; | ^^^^^^^^^^^^^^^^ 309| height: 50rpx; | ^^^^^^^^^^^^^^^^^^^ 310| justify-content: center; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 311| align-items: center; | ^^^^^^^^^^^^^^^^^^^^^^^^^ 312| } | ^^ 313| | ^ 314| .search-bar-box { | ^^^^^^^^^^^^^^^^^^ 315| display: flex; | ^^^^^^^^^^^^^^^^^^^ 316| width: 500rpx; | ^^^^^^^^^^^^^^^^^^^ 317| height: 50rpx; | ^^^^^^^^^^^^^^^^^^^ 318| border: 1rpx solid #000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 319| border-radius: 50rpx; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 320| align-items: center; | ^^^^^^^^^^^^^^^^^^^^^^^^^ 321| } | ^^ 322| | ^ 323| .search-span { | ^^^^^^^^^^^^^^^ 324| width: 70rpx; | ^^^^^^^^^^^^^^^ 325| height: 45rpx; | ^^^^^^^^^^^^^^^^ 326| margin-left: 20rpx; | ^^^^^^^^^^^^^^^^^^^^^ 327| } | ^^ 328| | ^ 329| .search-text { | ^^^^^^^^^^^^^^^ 330| width: 100%; | ^^^^^^^^^^^^^^^^^ 331| font-size: 24rpx; | ^^^^^^^^^^^^^^^^^^^^^^ 332| color: #7f7f81; | ^^^^^^^^^^^^^^^^^^^^ 333| text-align: center; | ^^^^^^^^^^^^^^^^^^^^^^^^ 334| } | ^^ 335| | ^ 336| .search-btn { | ^^^^^^^^^^^^^^ 337| background-color: #f5f5f5; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 338| text-align: center; | ^^^^^^^^^^^^^^^^^^^^^^^^ 339| display: inline-block; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 340| font-size: 24rpx; | ^^^^^^^^^^^^^^^^^^^^^^ 341| width: 150rpx; | ^^^^^^^^^^^^^^^^^^^ 342| height: 50rpx; | ^^^^^^^^^^^^^^^^^^^ 343| line-height: 50rpx; | ^^^^^^^^^^^^^^^^^^^^^^^^ 344| border-radius: 30rpx; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 345| letter-spacing: 3rpx; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 346| } | ^^ 347| .pickers{ | ^^^^^^^^^^ 348| display: flex; | ^^^^^^^^^^^^^^^^^^^ 349| } | ^^ 350| .pickers picker { | ^^^^^^^^^^^^^^^^^^ 351| flex:1; | ^^^^^^^^^^^^ 352| text-align: center; | ^^^^^^^^^^^^^^^^^^^^^^^^ 353| background-color: #fff; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 354| margin: 20rpx; | ^^^^^^^^^^^^^^^^^^^ 355| padding: 20rpx; | ^^^^^^^^^^^^^^^^^^^^ 356| } | ^^ 357| </style> | ^^^^^^^^ Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <style>, as they will not be parsed. 287| }); 288| </script> 289| | 290| <style scoped> | ^^^^^^^^^^^^^^ 291| .content{ | ^^^^^^^^^^ 292| background-color: #f5f5f5; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 293| } | ^^ 294| .header { | ^^^^^^^^^^ 295| display: flex; | ^^^^^^^^^^^^^^^^^^^ 296| padding: 10rpx 5rpx; | ^^^^^^^^^^^^^^^^^^^^^^ 297| background-color: #fff; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 298| justify-content: center; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 299| align-items: center; | ^^^^^^^^^^^^^^^^^^^^^^^^^ 300| } | ^^ 301| | ^ 302| .logo { | ^^^^^^^^ 303| height: 80rpx; | ^^^^^^^^^^^^^^^^ 304| width: 300rpx; | ^^^^^^^^^^^^^^^^ 305| } | ^^ 306| | ^ 307| .search-bar { | ^^^^^^^^^^^^^^ 308| width: 80%; | ^^^^^^^^^^^^^^^^ 309| height: 50rpx; | ^^^^^^^^^^^^^^^^^^^ 310| justify-content: center; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 311| align-items: center; | ^^^^^^^^^^^^^^^^^^^^^^^^^ 312| } | ^^ 313| | ^ 314| .search-bar-box { | ^^^^^^^^^^^^^^^^^^ 315| display: flex; | ^^^^^^^^^^^^^^^^^^^ 316| width: 500rpx; | ^^^^^^^^^^^^^^^^^^^ 317| height: 50rpx; | ^^^^^^^^^^^^^^^^^^^ 318| border: 1rpx solid #000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 319| border-radius: 50rpx; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 320| align-items: center; | ^^^^^^^^^^^^^^^^^^^^^^^^^ 321| } | ^^ 322| | ^ 323| .search-span { | ^^^^^^^^^^^^^^^ 324| width: 70rpx; | ^^^^^^^^^^^^^^^ 325| height: 45rpx; | ^^^^^^^^^^^^^^^^ 326| margin-left: 20rpx; | ^^^^^^^^^^^^^^^^^^^^^ 327| } | ^^ 328| | ^ 329| .search-text { | ^^^^^^^^^^^^^^^ 330| width: 100%; | ^^^^^^^^^^^^^^^^^ 331| font-size: 24rpx; | ^^^^^^^^^^^^^^^^^^^^^^ 332| color: #7f7f81; | ^^^^^^^^^^^^^^^^^^^^ 333| text-align: center; | ^^^^^^^^^^^^^^^^^^^^^^^^ 334| } | ^^ 335| | ^ 336| .search-btn { | ^^^^^^^^^^^^^^ 337| background-color: #f5f5f5; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 338| text-align: center; | ^^^^^^^^^^^^^^^^^^^^^^^^ 339| display: inline-block; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 340| font-size: 24rpx; | ^^^^^^^^^^^^^^^^^^^^^^ 341| width: 150rpx; | ^^^^^^^^^^^^^^^^^^^ 342| height: 50rpx; | ^^^^^^^^^^^^^^^^^^^ 343| line-height: 50rpx; | ^^^^^^^^^^^^^^^^^^^^^^^^ 344| border-radius: 30rpx; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 345| letter-spacing: 3rpx; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 346| } | ^^ 347| .pickers{ | ^^^^^^^^^^ 348| display: flex; | ^^^^^^^^^^^^^^^^^^^ 349| } | ^^ 350| .pickers picker { | ^^^^^^^^^^^^^^^^^^ 351| flex:1; | ^^^^^^^^^^^^ 352| text-align: center; | ^^^^^^^^^^^^^^^^^^^^^^^^ 353| background-color: #fff; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 354| margin: 20rpx; | ^^^^^^^^^^^^^^^^^^^ 355| padding: 20rpx; | ^^^^^^^^^^^^^^^^^^^^ 356| } | ^^ 357| </style> | ^^^^^^^^ tag <view> has no matching end tag. 1 | 2 | <view class="content"> | ^^^^^^^^^^^^^^^^^^^^^^ 3 | 4 | <!-- 顶部 --> at C:\Users\wang\Desktop\speedragon\page_index\car-sector\car-sector.vue:0
最新发布
06-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值