我使用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
在我的打字稿项目中,我使用的是 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) 我想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)
我试图重现本教程,但我被困住了,不知道我错过了什么。
{{ …
注意:代码使用的是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) package.json visual-studio-code npm-scripts vscode-settings vscode-debugger
使用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 属性。
我已经在 上配置了电子邮件地址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如果我不输入此字段,它可以默认为我设置的电子邮件地址吗?我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)
如何解决这个问题?
喜欢标题,关于链接:
新的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) map.setsass文档给出的示例不起作用,为什么呢?
@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)\nRun Code Online (Sandbox Code Playgroud)\n我的sass版本是1.32.5.
\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)\nRun Code Online (Sandbox Code Playgroud)\n我希望设置地图时不会抛出错误。
\njavascript ×4
vue.js ×4
vuejs3 ×3
node.js ×2
typescript ×2
css ×1
dart-sass ×1
eslint ×1
git ×1
jsx ×1
npm ×1
npm-cli ×1
npm-login ×1
npm-scripts ×1
package.json ×1
python ×1
reactjs ×1
sass ×1
sass-loader ×1
sass-maps ×1
v-model ×1
v8 ×1
windows ×1