Javascript Vue.js中是否计算了多个.include?

Javascript Vue.js中是否计算了多个.include?,javascript,vue.js,methods,computed-properties,Javascript,Vue.js,Methods,Computed Properties,我试图在Vue.js中计算多个.includes和.filters,但未能成功 HTML: 高级[测试版] 除非另有说明,所有9mm和9×19mm均为9×19mm抛物面。除非另有说明,否则所有火灾率均为半自动 规定的。 **-仍处于测试阶段(测试地点) 名称 口径 范围(最大-最小)(螺柱) 损坏 容量 火速 损伤乘数(头部/躯干) 描述 等级解锁 {{list.name} {{list.cal}} {{list.r}} {{list.dmg} {{list.cap}} {{list.rp

我试图在Vue.js中计算多个.includes和.filters,但未能成功
HTML:


高级[测试版]

除非另有说明,所有9mm和9×19mm均为9×19mm抛物面。除非另有说明,否则所有火灾率均为半自动
规定的。

**-仍处于测试阶段(测试地点)

名称 口径 范围(最大-最小)(螺柱) 损坏 容量 火速 损伤乘数(头部/躯干) 描述 等级解锁 {{list.name} {{list.cal}} {{list.r}} {{list.dmg} {{list.cap}} {{list.rpm} {{list.multi}} {{list.desc}} {{list.rank} {{sortedList.length}}
JS

因此,我尝试使用多个.includes和.filter过滤器(我需要另一个过滤器,如
list=>list.name.includes(this.filterByCal)
,并使用“v-model='filterByCal'添加另一个输入” 叹息 有什么有用的答案吗?
最后一个有助于安排,但不是我想要的。因此,我真的需要som帮助!

排序函数错误地假设所有值都是数字:

.sort((a,b)=>a[this.sortBy]-b[this.sortBy])❌ 值不是数字
这些值实际上是字符串,减去一个字符串将得到
NaN
,因此排序将中断

要解决此问题,您可以检查字符串中的数字,然后才使用数值差。否则,请使用执行比较:

.sort((a,b)=>{
const aVal=a[这个.排序]
const bVal=b[这个.排序]
//仅在值为数字时检查差异
如果(/^\d+$/.test(aVal)和&/^\d+$/.test(bVal)){
返回aVal-bVal
}否则{
返回aVal.localeCompare(bVal)
}
})

嗯,我想你不明白我的意思(但这一个工作得更好),因为我要求在
computed
属性中使用多个.filter…如何?
function handleInput(e) {
  var ss = e.target.selectionStart
  var se = e.target.selectionEnd
  e.target.value = e.target.value.toUpperCase()
  e.target.selectionStart = ss
  e.target.selectionEnd = se
}

new Vue({
  el: "#main",
  data: {
    heading: "PF Gun List (WIP)",
    lists: [
      {
        name: "M9",
        cal: "9×19mm",
        dmg: "35-10",
        cap: "15+1 / 105",
        rpm: "780",
        multi: "1.50/1.10",
        desc:
          "A 9mm Italian pistol. One of the first 'wonder nines'. High capacity with deep reserves, light recoil, and high velocity. ",
        r: "40-80",
        rank: "0",
      },
      {
        name: "GLOCK 17 (G17)",
        cal: "9×19mm",
        dmg: "34-10",
        cap: "17+1/102",
        rpm: "780",
        r: "40-90",
        multi: "1.50/1.10",
        desc:
          "A 9mm Austrian pistol renowned for its simplicity and ruggedness. Compared to the M9, it has a higher capacity, but less muzzle velocity.",
        rank: "0",
      },
      {
        name: "M1911",
        cal: ".45 ACP",
        dmg: "48-29",
        cap: "8+1/56",
        rpm: "720",
        r: "55-90",
        multi: "1.40/1.15",
        desc:
          "A classic American pistol brought into the modern age. Very high damage up close, with poor velocity and small magazine size.",
        rank: "8",
      },
      {
        name: "DESERT EAGLE (DEAGLE) L5",
        cal: ".44 MAGNUM",
        dmg: "56-32",
        cap: "8+1/40",
        rpm: "400",
        r: "50-80",
        multi: "2.00/  1.30",
        desc:
          "A modern version of the iconic Israeli-American pistol. This specific model has been lightened as well as upgraded with dual Picatinny rails and a much-needed muzzle brake. Very high damage with the capacity to instantly kill to the head up close, with rough recoil.",
        rank: "18",
      },
      {
        name: "M45A1",
        cal: ".45 ACP",
        dmg: "45-28",
        cap: "10+1/60",
        rpm: "670",
        r: "50-95",
        multi: "1.40/1.15",
        desc:
          "A modern American pistol with many custom parts. High damage, medium capacity, strong recoil.",
        rank: "34",
      },

      {
        name: "FIVE SEVEN",
        cal: "5.7×28mm",
        dmg: "29-22",
        cap: "20+1/100",
        rpm: "800",
        r: "80-120",
        multi: "1.40/1.20",
        desc:
          "A modern Belgian pistol firing a unique caliber. Poor close-in performance, with great ranged performance, high velocity, large magazine, wall penetration and deep reserves.",
        rank: "57",
      },
      {
        name: "ZIP 22",
        cal: ".22 LONG RIFLE",
        dmg: "15-12",
        cap: "10+1/180",
        rpm: "1000 SEMI",
        r: "30-60",
        multi: "2.80/1.00",
        desc:
          "A modern American 'pistol' with questionable quality. Abysmal damage, but with deep reserves and a high headshot multiplier. A weapon so bad it killed a million dollar company. 3 shots to the head at all ranges.",
        rank: "61",
      },
      {
        name: "DESERT EAGLE (DEAGLE) XIX",
        cal: ".50 ACTION EXPRESS",
        dmg: "72-37",
        cap: "7+1/21",
        rpm: "400",
        r: "40-82",
        multi: "2.50/1.40",
        desc:
          "Finally, a gun that lets you make a statement. This semi-automatic hand cannon is chambered in .50 Action Express. It'll probably pulverize your wrists with its recoil, but hey, you can't argue with the stopping power. And you've got the king of mayhem...",
        rank: "102",
      },
      {
        name: "GLOCK 18 (G18)",
        cal: "9×19mm",
        dmg: "30-20",
        cap: "19+1/57",
        rpm: "1100 AUTO",
        multi: "1.40/1.00",
        r: "20-60",
        desc:
          "A 9mm Austrian machine pistol. Fast fire rate with relatively stable handling characteristics.",
        rank: "17",
      },
    ],
    sortBy: "rank",
    filterByName: "",
    counter: 0,
  },

  computed: {
    sortedlists() {
      return this.lists
        .filter((list) => list.name.includes(this.filterByName))
        .sort((a, b) => a[this.sortBy] - b[this.sortBy])
    },
  },
})