代码内容

  1. function() {
  2. return {
  3. // 组件初始化
  4. init: function (options) {
  5. this._super.apply(this, arguments);
  6. let newlistId = 'a164793834068171';
  7. const imgUrl = './attach/imgs/xuanzhong.png';
  8. const templ = `
  9. <style id=${newlistId}_click_bgc_style>
  10. #${newlistId} .nl-row .nl-col.newList_click_bgc {
  11. background: url(${imgUrl});
  12. background-size: 100% 100%;
  13. background-repeat: no-repeat;
  14. }
  15. </style>
  16. `;
  17. $('body').prepend(templ);
  18. },
  19. // 容器内所有组件加载完成
  20. allChildrenLoaded: function () {
  21. },
  22. componentsRendered: function () {
  23. let newlistId = 'a164793834068171';
  24. $('#' + newlistId).find('.nl-col').eq(0).addClass('newList_click_bgc')
  25. $('#' + newlistId).parent().on('click', '.nl-col', (e) => {
  26. $(`#${newlistId} .newList_click_bgc`).removeClass('newList_click_bgc');
  27. $(e.currentTarget).addClass('newList_click_bgc');
  28. });
  29. }
  30. };
  31. }

使用说明

  1. 1、newlistId 更改id 为现场使用的id<br />2、imgUrl :选中新闻列表出现的选中图片效果

效果说明

进入后,默认选中新闻列表第一条,点击某条,则产生对应的选中效果,其他行取消选中效果;