Category Archives: Javasript

[Solved] React Issue: Selected Style Not Working

Source code:

<NavLink to="/home1" activeClassName="selected"> Home Page 1</NavLink>
        <NavLink activeStyle={{
            fontWeight: 'bold',
            color: 'red'}}
          to="/home2"> Home Page 2
        </NavLink>

report errors:

index.js:1 Warning: React does not recognize the `activeClassName` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `activeclassname` instead. If you accidentally passed it from a parent component, remove it from the DOM element.

First check your version:

All versions above V6 will report this error. Just change back to V5. At the same time, if you use <Routes> Please delete this V6 attribute

How to Solve Vue3 ts setup getCurrentInstance Error

environment

vscode

typescript4

vue3

Problem description

First of all, the configuration of global variables and methods in vue3 is different from that in vue2. If you are not clear, you can check the official instructions, but you encounter problems when using them in combination with typescript :

axios.ts

// axios.ts
import axios from 'axios'
const app = Vue.createApp({})

// Global Custom Properties
declare module '@vue/runtime-core' {
  interface ComponentCustomProperties {
    $axios: AxiosInstance;
  }
}

app.config.globalProperties.$axios = axios

Any Vue file

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

// First, here the proxy ts will report
// Property "proxy" does not exist on type "ComponentInternalInstance | null". ts(2339)
const { proxy } = getCurrentInstance()

// Then this error will be reported below
// Unsafe member access .$axios on an `any` value.  eslint@typescript-eslint/no-unsafe-member-access
// Unsafe call of an `any` typed value.  eslint@typescript-eslint/no-unsafe-call
proxy.$axios('')

The above is the whole content of error reporting. Next, let’s solve this problem

Problem-solving:

The first error is easy to understand. Because the return type of getcurrentinstance() has null, you can add assertions here

import { ComponentInternalInstance, getCurrentInstance } from 'vue';
// Add Assertion
const { proxy } = getCurrentInstance() as ComponentInternalInstance

2. However, after the correction, we found that there are still errors reported below

// Object may be "null".ts(2531)
proxy.$axios('')

This problem is easier to solve. Add after proxy to filter the results of null

proxy?.$axios('')

Above, the problem is solved!

Uncaught (in promise) NavigationDuplicated [How to Solve]

The reason is: Vue router is in 3 After the X version, put this$ router. The replace () method is changed to promise. If there is no callback function, the error message will be displayed globally

Solution:

1. Reduce Vue router version to 3.0 Below 7

npm install [email protected] -s

2. Add a callback for this.$router.replace() method

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}

[Solved] VScode error: vetur can’t find ‘tsconfig. JSON’ or ‘jsconfig. JSON’. Solution to red wave error “vetur. Ignoreprojectwarning”: true,

    // VSCode Error: Vetur can't find 'tsconfig.json' or 'jsconfig.json' solution, Red wave error solution
    "vetur.ignoreProjectWarning": true,
    "eslint.enable": false,
    "vetur.validation.template": false,
    "files.associations": {
        "*.vue": "html"
    }

[Solved] ant Error: Cannot use ‘in’ operator to search for ‘value’ in undefined

ant Error:  Cannot use ‘in’ operator to search for ‘value’ in undefined  at getValuePropValue (util.js:29)
When using the multi-select Select component again, an error is reported as shown in the figure

The reason is because the value is assigned before the options is rendered.

let children = List.length && List.map((item) => {
            return{item.userName}
        })

Delete the Bold codes as follow:

1 let children =  shapeExpertsList.map((item) => {
2             return <Option name={item.userName} key={item.userId} value={item.userId} >{item.userName}</Option>
3         }

[Solved] vue-pdf Cannot read properties of undefined (reading ‘catch’)

Error reporting after dependent installation

TypeError: Cannot read properties of undefined (reading 'catch')
    at PDFJSWrapper.renderPage (pdfjsWrapper.js?a068:196)
    at VueComponent.resize (componentFactory.js?0d60:75)
    at invokeWithErrorHandling (vue.esm.js?a026:1872)
    at VueComponent.invoker (vue.esm.js?a026:2197)
    at invokeWithErrorHandling (vue.esm.js?a026:1872)
    at VueComponent.Vue.$emit (vue.esm.js?a026:3912)
    at VueComponent.handler (resize-sensor.vue?c7ed:49)
    at invokeWithErrorHandling (vue.esm.js?a026:1872)
    at Watcher.run (vue.esm.js?a026:4593)
    at flushSchedulerQueue (vue.esm.js?a026:4335)

 

Solution:

lock the dependent version

npm and [email protected]

npm and [email protected]

 

pacakge.json

“pdfjs-dist”: “2.5.207”,

“vue-pdf”: “4.2.0”