小编Dre*_*lug的帖子

Vue3 检查插槽是否为空

Vue3 是否有相当于以下 Vue2 方法:

methods: {
   hasSlot(name) {
      return !!this.$slots[name]
   }
}
Run Code Online (Sandbox Code Playgroud)

在 Vue3 的 Composition API 中?

我试过了:

setup({slots}) {
   const hasSlot = (name) => {
      return !!slots[name];
   }

   return { hasSlot }

}
Run Code Online (Sandbox Code Playgroud)

但它没有返回预期值,因为slots未定义(控制台中的每个错误)。

vue.js vuejs3

23
推荐指数
2
解决办法
2万
查看次数

未定义模板 'std::__1::basic_ifstream 的隐式实例化

我需要在一个项目的多个类中使用 iostream,但出现此错误。我曾尝试在其他地方添加 inputStream,但我不完全确定问题是什么。(我在标题中包含 iostream)。

g++    -c -o Agency.o Agency.cpp
Agency.cpp:48:19: error: implicit instantiation of undefined template
      'std::__1::basic_ifstream<char, std::__1::char_traits<char> >'
    std::ifstream inputStream;
                  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iosfwd:131:32: note: 
      template is declared here
    class _LIBCPP_TEMPLATE_VIS basic_ifstream;
                               ^
1 error generated.
make: *** [Agency.o] Error 1
Run Code Online (Sandbox Code Playgroud)

有小费吗?(这是在 C++ 中)代码如下:

void Agency::readAllData(Agency& agency, char *file) {
int i = 0;
char ch;
int tSensors = 0;

char Name[NAME_LENGTHS];
int ZIP[ZIP_LENGTH];

int Year;
char Make[NAME_LENGTHS];
char Model[NAME_LENGTHS];
float Price;
char sensorName[NAME_LENGTHS];
bool bAvailable;
char Owner[NAME_LENGTHS];

char strGPS[4] = …
Run Code Online (Sandbox Code Playgroud)

c++

5
推荐指数
0
解决办法
3085
查看次数

分而治之算法找到最大元素的位置

我试图使用分治算法找到数组中最大元素的索引。目前,输出正确输出了数组的最大值,但我无法弄清楚如何传递该最大元素的位置。

#include <iostream>

using namespace std;  


int maxElement(int a[], int l, int r) {
   if(r - l == 1) {
        cout << "R - L == 1 " <<  "Array value: " << a[l] << " Pos: " << l << endl;
        return a[l];
   }
   int m = (l + r) / 2;
   int u = maxElement(a, l, m);
   int v = maxElement(a, m, r);
   return u > v ? u : v;    
}

/* Driver program to test above …
Run Code Online (Sandbox Code Playgroud)

c++ sorting

5
推荐指数
1
解决办法
2346
查看次数

Vue3等待子组件安装完毕

我想在渲染工具提示之前等待子组件安装。在等待时,我将有一个占位符显示给用户。

一个示例组件是:

<template>
   <div v-if="!mounted">Loading...</div>
   <child-component></child-component>
</template>
<script>
export default defineComponent({
   setup() {
       const mounted = ref(false);       

       return { 
           mounted
       } 
   }
});
</script>
Run Code Online (Sandbox Code Playgroud)

经过研究,Vue2 似乎支持组件的生命周期挂钩,这会将上面的代码更改为:

<template>
   <div v-if="!mounted">Loading...</div>
   <child-component @hook:mounted="mountedCheck"></child-component>
</template>
<script>
export default {
export default defineComponent({
   setup() {
       const mounted = ref(false);       
       const mountedCheck = () = {
           mounted.value = true;
       }       

       return { 
           mounted, mountedCheck
       } 
   }
});
}
Run Code Online (Sandbox Code Playgroud)

但是,我似乎无法开始@hook:mounted工作。Vue3 中是否有类似的东西,或者我错过了什么?

vuejs3

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

JSON 字符串化每行一个对象

是否可以将以下内容字符串化为预期输出?

输入:

let output = JSON.stringify([
   {
     "Color": "Red", 
     "Type":"Fast"
   },
   {
     "Color": "Blue", 
     "Type":"Slow"
   }
]);
Run Code Online (Sandbox Code Playgroud)

预期输出:

[
   {"Color": "Red", "Type":"Fast"},
   {"Color": "Blue", "Type":"Slow"}
]
Run Code Online (Sandbox Code Playgroud)

javascript json

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

标签 统计

c++ ×2

vuejs3 ×2

javascript ×1

json ×1

sorting ×1

vue.js ×1