Tag Archives: javascript

[Solved] mqtt.js Error: n.createConnection is not a function

Reason: This is a version problem, 4.2.X+ (this is also the problem when I use the latest version, which may be improved in the future)

Solution: use the lower version, I use 4.1.X is OK.

Here is the output of the client after the connection is successful

Vue solution:
Vue installation. Not only the version needs to be modified, but also the ^  in front of the version needs to be removed (in packpage.json), but there is no Vue test. You can try it (a picture of other blogs is cut here)

[Solved] JSON.parse() Error: Unexpected end of JSON input

Error returned during JSON.parse() conversion due to conversion characters or other special characters in the data of the converted JSON.stringify().

Solution:

encoding before the JSON.stringify() transformation and decoding the operation when JSON.parse() is solved.

Example:

Jump pass parameter

 toEdit() {
    this.data.userInfo.faceData = this.data.faceData
    let info = encodeURIComponent(JSON.stringify(this.data.userInfo))
    wx.navigateTo({
      url: '../userEdit/userEdit?info=' + info 
    })
  },

receive data

onLoad(options) {
	//decodeURIComponent decoding
   let info = JSON.parse(decodeURIComponent(options.info))
   this.setData({info:info})
}

[Solved] Error: Incorrect arguments to mysqld_stmt_execute

When mysql2 is used to operate the database in express, the paging query will report an error error incorrect arguments to mysqld_stmt_execute

Question

Error reporting: error: incorrect arguments to mysqld_stmt_execute

// Query notes based on number of notes and number of pages
  async getSomeNote(num, page) {
    const fromNum = (page - 1) * num
    const statement = `SELECT id,note_title,note_describe,note_createtime,note_sort FROM notes_test LIMIT ? ,? ;`
    // There is a problem with the parameters fromNum, num passed in here, they are numeric at this point
    const result = await connections.execute(statement, [fromNum, num])
    console.log(result[0]);
    return result[0]
  }

reason

Statement is a query statement for operating the database and is of string type. The contents of the second parameter of execute will be inserted into the statement. At this time, the number type inserted should be of string type, so an error “wrong parameter” is reported.

Solution:

Change the passed in parameter to string type.

// Query notes based on number of notes and number of pages
  async getSomeNote(num, page) {
    const fromNum = (page - 1) * num
    const statement = `SELECT id,note_title,note_describe,note_createtime,note_sort FROM notes_test LIMIT ? ,? ;`
    // Direct string concatenation, converting number types to character types
    const result = await connections.execute(statement, [fromNum+'', num+''])
    console.log(result[0]);
    return result[0]
  }

[Solved] Vuex Error: unknown action type: changeUserInfo

Analyze the reason: this means that the method in actions cannot be read;

Troubleshooting:

Check whether there is a problem with the introduction:

1. In store/mutations.js If the exposure mode is export, you need to add {} when importing, as shown in the following code:

//export:

export {
    state,mutations,getters 
}

//import in store/index.js:
import {state,mutations,getters} from './mutations'

2. In store/actions.js If the exposure method is export default, you do not need to add {} when importing, as shown in the following code:

//export default:
export default {
    // modify userInfo
    changeUserInfo(context,obj){
        context.commit('changeUserInfo',obj);
        localStorage.setItem("userInfo",JSON.stringify(obj))
    }
}

//import in store/index.js:
import actions from './actions'

[Solved] nodejs Error: request entity too large

A project written in Vue and nodejs requires image upload, but report error:

PayloadTooLargeError: request entity too large
at readStream

Solution: add Middleware

const bodyParser = require('body-parser');
router.use(bodyParser.urlencoded({extended: false, limit: '10mb'}));

The default is 100kb, which can be replaced by a large number. The unit can be MB, etc

Node.js Error: Cannot find module express [How to Solve]

1. Install the express framework globally, CMD open the command line, and enter the following command:

    npm install -g express

In the express 4.x version, the command tool is separated, a command tool is installed, and the command is executed:

    npm install -g express-generator

type express --version

2. If execute js file report error: Error: Cannot find module express

Solution:
execute it again under your own project directory:
npm install express

[Solved] error Component name “xxx“ should always be multi-word vue/multi-word-comp

Project issues

An error was encountered in the Vue project today. The console reported error Component name “xxx“ should always be multi-word vue/multi-word-comp, which is mainly the error reported by eslint standardization

 

Solution:

Turn off naming rule verification
find it in the root directory eslintrc.js file, add the following code:

   "vue/multi-word-component-names":"off",

.eslintrc.js file content:

[Solved] Uncaught (in promise) DOMException: Failed to load because no supported source was found.

The audio error of uniapp,
my situation is that sometimes it is good and sometimes it is not good
the error report is shown in the figure below:

the reason for the error report is that the audio cannot find resources
check the code and find that the path is written like this

so the following modifications are made:
just import it directly above


solved~

Failed to execute ‘setRequestHeader’ on ‘XMLHttpRequest’: String contains non ISO-8859-1 code point.

When the front-end page sends a request to the background, non-english is put into the request header, so there will be coding format problems

Error message:

Failed to execute ‘setRequestHeader’ on ‘XMLHttpRequest’: String contains non ISO-8859-1 code point.

 

Solution:

Encoding: encodeURIComponent(str)
decoding: decodeURIComponent(str)

Request processing failed; nested exception is java.lang.NullPointerException or UnsatisfiedDependencyE

1. Null pointer exception:

Request processing failed; nested exception is java.lang.NullPointerException

java.lang.NullPointerException
com.atguigu.mvc.controller.NodesController.getFilesAndSendId(NodesController.java:61)


See the exception address and check the control layer

Control level, line 61:

List<FilePath> files = fileService.getFiles();

current

@RequestMapping(value = "/getFilesAndSendId/{sensor_id}",method = RequestMethod.GET)

Parameter sensor_id is passed;

Solution to null pointer:
Original:

private FileService fileService;

Change to: add @Autowired annotation

 @Autowired
    private FileService fileService;

If there is any other error when you run the codes:

Servlet.init() of Servlet[DispatcherServlet] raises an exception.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘nodesController’: Unsatisfied dependency expressed through field ‘fileService’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.atguigu.mvc.service.FileService’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


Solution:
Check if the @Service annotation is added to the implementation class here

[Solved] Front end error: Unknown custom element

report errors

chunk-vendors.js:2128 [Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the “name” option. - did you register the component correctly?For recursive components, make sure to provide the "name" option

 

reason

el component not registered

Solution:

1. Download elementUI

npm i element-ui -S

2. Import

Add the following three lines  in main.js:

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

Done!

eslint Error: Delete `␍` [How to Solve]

reason

Due to the end of line style configuration, endoofline configuration has the following four options:
lf – line feed only (\n), which is common in Linux, MacOS and git repos
CRLF – carriage return + line feed character (\r \n), and windows
CR – carriage return character only (\r), Rarely use
auto – keep the existing end of the line (the mixed values in a file are standardized by looking at the content used after the first line)


Solution:

Configure endOfLine: ‘auto’ in prettier.config.js:

module.exports = {
  semi: false, // unterminated semicolon
  singleQuote: true, // single quotes
  quoteProps: 'as-needed',
  trailingComma: 'none', // final comma
  
 // The point is that this one should be configured as auto
  endOfLine: 'auto'
}