小编Vas*_*try的帖子

了解如何避免 VueJS 中的 vue/require-prop-type-constructor 警告

我正在控制一个带有布尔变量的 TabviewisTabsEnabled来切换选项卡的显示。这个道具作为子文件传递给使用它的屏幕,这是父文件,

export{
  props:{
    isTabsEnabled: true
  }
}
Run Code Online (Sandbox Code Playgroud)

ESLint 抛出错误vue/require-prop-type-constructor,我尝试使用propsData,这会删除警告消息,但功能中断。

关于如何避免此警告的任何建议?

vue.js

4
推荐指数
1
解决办法
5908
查看次数

处理计算属性中的意外副作用-VueJS

在下面的代码中,我试图使用该getTranslation对象映射originalKeysarray中存在的值并将值推入新的array中allKeys

但是ESLint给我这个错误, Unexpected side effect in "getkeys" computed property.

我尝试将getkeys函数转换为方法,但是我认为每次都调用一个方法来完成翻译是没有意义的。我该如何解决这个问题?

<template>
    <select v-model="selected">
    <option v-for="key in getkeys" v-bind:key="key"> {{ key }}</option
    </select>
</template>

data(){
    return{
    selected: '',
    allKeys: [],
    originalKeys: [],  //e.g. ["ALPHA_MIKE]
    getTranslation: {} //e.g. {"ALPHA_MIKE": "ALPHA MIKE"}
    }
},
computed: {
    getkeys(){
        let tableHeaders = [];
        for( var i=0; i<this.originalKeys.length; i++){
            let translation = this.getTranslation[this.originalKeys[i]];
            tableHeaders.push(translation);
        }
        this.selected = tableHeaders[0]; //unexpected side effect here
        this.allKeys = tableHeaders; //unexpected side effect here.
        return …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vuejs2

3
推荐指数
3
解决办法
2163
查看次数

Java Lambdas:与 PriorityQueue 的比较器

考虑一个优先队列

PriorityQueue<Integer> heap = new PriorityQueue<Integer>();
Run Code Online (Sandbox Code Playgroud)

我可以在这里以两种方式定义比较器,一种是使用lambda,另一种是使用Comparator()

假设这两种方式对 2 个变量进行简单的整数比较,我想知道哪个变量是我们要比较的值,哪个变量包含队列中的现有值

例如:

    PriorityQueue<Integer> heap = new PriorityQueue<Integer>(new Comparator<Integer>() {
       @Override
        public int compare(Integer a, Integer b) {
            System.out.println(a+" "+b);
            return b-a;
        }
    });
Run Code Online (Sandbox Code Playgroud)

当我调用heap.add(2)后跟 a 时heap.add(3),第二个add()调用会触发compare(a,b)函数并打印a=3 & b=2,这意味着这里a有新值并且b是队列中的现有值

同样,你能告诉我下面的 lambda 表达式是否会类似地工作还是相反?

PriorityQueue<Integer> heap = new PriorityQueue<Integer>((a,b) -> b-a);
Run Code Online (Sandbox Code Playgroud)

我知道这个问题可以用更简单的方式写出来,但我现在无法做到。

此外,这两个打印相同的值,即降序 4,3,2,1

     PriorityQueue<Integer> heap2 = new PriorityQueue<Integer>(new Comparator<Integer>() {
       @Override
        public int compare(Integer a, …
Run Code Online (Sandbox Code Playgroud)

java lambda

0
推荐指数
1
解决办法
51
查看次数

标签 统计

vue.js ×2

java ×1

javascript ×1

lambda ×1

vuejs2 ×1