小编Wen*_* Du的帖子

如何在<script setup> Vue3中使用render函数

我使用Vue 3.1.1

我在实验阶段使用脚本设置和单个文件组件。使用脚本设置,我了解defineProps、defineEmit和useContext,但我不了解如何使用渲染函数。

<script lang="ts" setup>
import { defineProps } from 'vue'

const props = defineProps<{
    text: string
}>()

const handleClick = () => {
    console.log('click!!')
}

// Render function...

/* The template I want to create.
    <button
        class="btn btn-primary"
        type="button"
        @click="handleClick"
    >
        {{ props.text }}
    </button>
*/
</script>
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vuejs3 vue-composition-api vue-script-setup

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

如何修复 eslintrc 文件与您的项目配置不匹配?

在我的打字稿项目中,我使用的是 eslint。下面的文件在根目录中,我还有子文件夹/dist/src.

eslintrc.js

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  parserOptions: {
    tsconfigRootDir: __dirname,
    project: ['./tsconfig.json'],
  },
  rules: {
    strict: 'error',
    semi: ['error', 'always'],
    'no-cond-assign': ['error', 'always'],
  },
  plugins: ['@typescript-eslint'],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
  ],
}
Run Code Online (Sandbox Code Playgroud)

配置文件

{
  "compilerOptions": {
    "outDir": "dist",
    "noImplicitAny": true,
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "module": "ES2020",
    "target": "ES2020",
    "lib": ["ES2020"],
    "allowJs": false,
    "alwaysStrict": true
  },
  "include": ["src"]
}
Run Code Online (Sandbox Code Playgroud)

module顶部的单词有一条带有此错误的红线

Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does …
Run Code Online (Sandbox Code Playgroud)

node.js typescript eslint

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

如何在 vue 3 脚本设置中的组件上使用 v-model

我想v-model在组件上添加 a 但收到此警告:

[Vue warn]: Component emitted event "input" but it is neither declared in the emits option nor as an "onInput" prop.
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

[Vue warn]: Component emitted event "input" but it is neither declared in the emits option nor as an "onInput" prop.
Run Code Online (Sandbox Code Playgroud)
// Parent.vue
<template>
  <h2>V-Model Parent</h2>
  <Child v-model="name" label="Name" />
  <p>{{ name }}</p>
</template>

<script setup>
import { ref } from 'vue'
import Child from './Child.vue'

const name = ref('')
</script>
Run Code Online (Sandbox Code Playgroud)

我试图重现本教程,但我被困住了,不知道我错过了什么。

{{ …

vue.js v-model vuejs3 vue-composition-api vue-script-setup

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

可选链 - Function.prototype.apply 在 undefined 上被调用,这是一个 undefined 而不是函数

对函数调用使用可选链接会导致表达式自动返回 undefined 而不是在找不到方法时抛出异常。

注意:代码使用的是spread syntax,而不是rest parameters

const fn1 = undefined
const args = []
const fn2 = () => {}
const fn3 = () => {}

console.log(fn1?.(...args, fn2, fn3))
Run Code Online (Sandbox Code Playgroud)

错误:

console.log(fn1?.(...args, fn2, fn3))
                                ^
TypeError: Function.prototype.apply was called on undefined, which is an undefined and not a function
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome v8 node.js optional-chaining

16
推荐指数
1
解决办法
652
查看次数

如何禁止在 package.json 中显示“调试”

如何禁用概述的“调试”提示,使其不显示在该scripts部分上方的 package.json 中:

在此处输入图片说明

package.json visual-studio-code npm-scripts vscode-settings vscode-debugger

14
推荐指数
1
解决办法
6404
查看次数

为什么 kebab-case 非标准属性是允许的,而其他属性则不允许?以及如何在 TypeScript 中定义这样的类型?

使用foo作为属性抛出一个错误:

// App.tsx
//                      throws
const App = () => <div foo></div>

export default App
Run Code Online (Sandbox Code Playgroud)
Type '{ foo: true; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.
  Property 'foo' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.ts(2322)
Run Code Online (Sandbox Code Playgroud)

但使用foo-foo是好的,为什么呢?

// App.tsx
//                      no error is thrown
const App = () => <div foo-foo></div>

export default App
Run Code Online (Sandbox Code Playgroud)

最重要的是,如何在 TypeScript 中定义这样的类型?即只允许标准或 kebab-case 属性。

javascript jsx typescript reactjs vue.js

14
推荐指数
2
解决办法
348
查看次数

NPM - 关于“电子邮件:(这是公开的)”的问题

我已经在 上配置了电子邮件地址npmjs.com,为什么 cli 一直提示我输入电子邮件?

$ npm login
npm notice Log in on https://registry.npmjs.org/
Username: wenfangdu
Password:
Email: (this IS public)
Run Code Online (Sandbox Code Playgroud)

即使我输入的电子邮件与我设置的电子邮件不同npmjs.com,我仍然可以登录。

问题:

  • 输入这封电子邮件有什么意义?
  • npmjs.com如果我不输入此字段,它可以默认为我设置的电子邮件地址吗?

npm npm-cli npm-login

13
推荐指数
1
解决办法
4645
查看次数

`git filter-repo` 命令在 Windows 上不输出任何内容

git-filter-repo通过安装scoop,尝试了多个git filter-repo命令,例如git filter-repo -h,它们都没有记录任何内容,没有警告或错误,只是没有记录

尝试重新启动、重新安装并在另一台 Windows 10 计算机上安装它,全部重现。

git-filter-repo: v2.33.0
git: v2.33.0.windows.2
python: v3.9.7
scoop:

Current Scoop version:
09200504 (HEAD -> master, origin/master, origin/HEAD) reset: skip when app instance is running (#4359)

'main' bucket:
b71f4a842 (HEAD -> master, origin/master, origin/HEAD) nunit-extension-vs-project-loader: Update to version 3.9.0
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?

python windows git scoop-installer git-filter-repo

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

如何在vue3的&lt;script setup&gt;中使用props

喜欢标题,关于链接: 新的script setup(不含参考糖)

<template>
  <TopNavbar title="room" />
  <div>
    {{ no }}
  </div>
</template>

<script setup>
import TopNavbar from '@/layout/TopNavbar.vue'
import { defineProps, reactive } from 'vue'

defineProps({
  no: String
})

const state = reactive({
  room: {}
})

const init = async () => {
  // I want use props in this
  // const { data } = await getRoomByNo(props.no)
  // console.log(data);
}
init()

</script>

<style>
</style>
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vuejs3 vue-script-setup

12
推荐指数
4
解决办法
8311
查看次数

为什么我会收到语法错误:SassError:预期“{”?

map.setsass文档给出的示例不起作用,为什么呢?

\n
@use "sass:map";\n\n$font-weights: (\n  \'regular\': 400,\n  \'medium\': 500,\n  \'bold\': 700\n);\n\nmap.set($font-weights, \'extra-bold\', 900);\n// ("regular": 400, "medium": 500, "bold": 700, "extra-bold": 900)\nmap.set($font-weights, \'bold\', 900);\n// ("regular": 400, "medium": 500, "bold": 900)\n
Run Code Online (Sandbox Code Playgroud)\n

我的sass版本是1.32.5.
\n整个错误消息:

\n
@use "sass:map";\n\n$font-weights: (\n  \'regular\': 400,\n  \'medium\': 500,\n  \'bold\': 700\n);\n\nmap.set($font-weights, \'extra-bold\', 900);\n// ("regular": 400, "medium": 500, "bold": 700, "extra-bold": 900)\nmap.set($font-weights, \'bold\', 900);\n// ("regular": 400, "medium": 500, "bold": 900)\n
Run Code Online (Sandbox Code Playgroud)\n

我希望设置地图时不会抛出错误。

\n

css sass sass-loader sass-maps dart-sass

9
推荐指数
1
解决办法
1万
查看次数