当我在 vue 3 设置代码块中编写此代码以获取遵循此答案的输入值时,这是代码的一部分:
import { defineComponent } from "vue";
import { defineProps, defineEmits } from 'vue'
export default defineComponent({
setup() {
const props = defineProps({
modelValue: String
})
const emit = defineEmits(['update:modelValue'])
function updateValue(value: any) {
emit('update:modelValue', value)
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序运行时显示错误:
option.js:17388 Uncaught TypeError: emit is not a function
at Proxy.updateValue (option.js:17388:13)
at onInput._cache.<computed>._cache.<computed> (option.js:17428:78)
at callWithErrorHandling (option.js:7359:22)
at callWithAsyncErrorHandling (option.js:7368:21)
at HTMLInputElement.invoker (option.js:15384:90)
Run Code Online (Sandbox Code Playgroud)
我已经定义了emit,为什么仍然告诉我emit不是一个函数?这是我的 vue3 组件的完整代码:
<template>
<div id="app">
<div id="wrap">
<label>
{{ username }}
</label> …Run Code Online (Sandbox Code Playgroud) typescript vue.js vuejs3 vue-composition-api vue-script-setup
我有一个遗留的 typescript React 应用程序,现在我想将其从 webpack 迁移到 vite,当我使用此命令构建应用程序时,显示如下错误:
\n> tsc && vite build\n\nvite v4.3.5 building for production...\n\xe2\x9c\x93 2 modules transformed.\n\xe2\x9c\x93 built in 32ms\n[vite]: Rollup failed to resolve import "/src/main.tsx" from "/Users/John/source/reddwarf/frontend/snap-web/src/index.html".\nThis is most likely unintended because it can break your application at runtime.\nIf you do want to externalize this module explicitly add it to\n`build.rollupOptions.external`\nerror during build:\nError: [vite]: Rollup failed to resolve import "/src/main.tsx" from "/Users/John/source/reddwarf/frontend/snap-web/src/index.html".\nThis is most likely unintended because it can break your application at runtime.\nIf you do want …Run Code Online (Sandbox Code Playgroud) 我有一个公共组件库调用rd-component,当我在新项目中使用此组件时"rd-component": "^0.1.47",Visual Studio代码显示如下错误:
Could not find a declaration file for module 'rd-component'. '/Users/John/source/reddwarf/frontend/ppt-web/node_modules/.pnpm/rd-component@0.1.47_@types+node@20.1.1_react-dom@18.2.0_react-redux@8.0.5_react@18.2.0_vite@4.3.2/node_modules/rd-component/dist/rd-component.es.js' implicitly has an 'any' type.
There are types at '/Users/John/source/reddwarf/frontend/ppt-web/node_modules/rd-component/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'rd-component' library may need to update its package.json or typings.ts(7016)
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能解决这个问题?这是公共 rd 组件的package.json:
{
"name": "rd-component",
"version": "0.1.47",
"type": "module",
"description": "Reddwarf public component lib",
"files": [
"dist"
],
"main": "./dist/rd-component.umd.js",
"module": "./dist/rd-component.es.js",
"types": "./dist/index.d.ts",
"exports": {
".": { …Run Code Online (Sandbox Code Playgroud) 我在 typescript 项目中添加了如下的 webpack 5 配置:
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry : {
'index' : './index.ts',
} ,
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
vue: 'vue/dist/vue.esm-bundler.js',
'@': path.resolve(__dirname, '../../../src'),
},
},
output : {
path : path.resolve(__dirname, '../../bundle') ,
filename : '[name].js'
},
module : {
rules : [
{
test: /\.ts$/,
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/]
},
include: [
path.resolve(__dirname, '../../../node_modules/js-wheel'),
path.resolve(__dirname, '../../../src')
],
exclude: /node_modules|\.d\.ts$/
}
]
} …Run Code Online (Sandbox Code Playgroud) 我一直用mini-css-extract-pluginCSS来优化。今天我发现了一个新项目,css-minimizer-webpack-plugin从这里看,这个项目似乎做了同样的事情mini-css-extract-plugin。
优点是什么css-minimizer-webpack-plugin?我读了谷歌的文档和文章,似乎没有人在谈论它?我应该用css-minimizer-webpack-plugin来替换mini-css-extract-plugin吗?
typescript ×4
reactjs ×2
vite ×2
css ×1
html ×1
javascript ×1
vue.js ×1
vuejs3 ×1
webpack ×1
webpack-5 ×1