小程序从数组中删除指定对象,返回新的长度源代码

news/2025/2/22 7:19:53

html

  <view data-index='{{index}}' bindtap='cancel'>删除</view>

 

js

cancel(e) {

let dynamicId = e.currentTarget.dataset.index//点击返回去的下标

let allNewsList = this.data.list//原始列表数组

 allNewsList.splice(dynamicId, 1);//删除指定下标

}

this.setData({

  list:allNewsList//返回新的列表长度

})

 


http://www.niftyadmin.cn/n/1367293.html

相关文章

小程序富文本设置图片大小

html <rich-text nodes"{{listmore}}"></rich-text> js this.setData({ contents:res.data.contents.replace(/\<img/gi, <img class"add" style"width:100%;height:auto")//class"add"我是设置了全局样式&am…

小程序自定义导航下标图片

html <view class"container"><!-- tab导航栏 --><!-- scroll-left属性可以控制滚动条位置 --><!-- scroll-with-animation滚动添加动画过渡 --><scroll-view scroll-x"true" class"nav" scroll-left"{{navScr…

vue下载图片,word,pdf,自定义下载名称

downloadFiles(url, name) {//url是路径&#xff0c;name是要更改的下载名称let link document.createElement(a)let url url// 这里是将url转成blob地址&#xff0c;fetch(url).then(res > res.blob()).then(blob > { // 将链接地址字符内容转变成blob地址link.href …

小程序一键拨打电话

tocall(e){console.log(e.currentTarget.dataset.phone)//获取的电话号码wx.makePhoneCall({phoneNumber: e.currentTarget.dataset.phone}).catch((e) > {// console.log(e) //用catch(e)来捕获错误{makePhoneCall:fail cancel}})},

小程序生成二维码

wxml <canvas canvas-idqrcode></canvas> js var QRCode require(../../utils/weapp-qrcode.js); var qrcode/*** 生命周期函数--监听页面加载*/onLoad: function (options) {qrcode new QRCode(qrcode, { //qrcode为html中定义的canvas-idtext: "http…

微信公众号授权前端(uniapp为例)

const base_url http://baidu.com// 前端域名const wx_url https://open.weixin.qq.com/connect/oauth2/authorize?appidappid&redirect_uribase_url&response_typecode&scopesnsapi_base&state123#wechat_redirectexport default {components: {},data() {…

vue本地存储

localStorage.setItem(token, res.Msg.token); localStorage.getItem(token);//uniuni.setStorageSync(token, 123456) uni.getStorageSync("token"); uni.removeStorageSync(token);//移除//小程序 wx.setStorageSync(key, value)//arr是要存的数据 wx.getStorageSy…

vue移动端(element为例)上传多张图片

<template><div class"about"><!-- 列表 --><div class"center"><p><input v-model"name" placeholder"请输入标题" /></p><!-- 详细信息 --><div class"mark"><…