Tag Archives: javascript

After Vue is packaged, a blank page appears, an error is reported in the resource request, and there is no error handling scheme

1、 A blank page appears and an error is reported

        Scheme I:

                 1: The path of JS and CSS resources is incorrect

                 Solution: add assetspublicpath in config/index.js: ‘/’   Change to assetspublicpath: ‘. /’  

                 2: Error in background image in CSS

                 Solution: add a line of code in build/utils.js   publicPath:’../../’  

        Scheme 2: some people may create Vue basic projects through hbuilder. There are no files in scheme 1 in the directory. Then you can try the scheme at this time. It’s easy to use on my side. I’m not sure everyone is effective.

                Solution: create the vue.config.js file in the project root directory

 

  The contents of the document are as follows:

module.exports = {
    publicPath : './'
}

2、 Blank page, no resource error

        At this time, the problem may be caused by the routing mode

  history :

The new pushstate () and replacestate () methods in HTML5 history interface are utilized. (specific browser support is required) these two methods are applied to the browser’s history stack. On the basis of the existing back, forward and go, they provide the function of modifying the history. Only when they perform modification, although the current URL is changed, the browser will not immediately send a request to the back end.

Solution:

The default route of Vue is hash mode. You can modify it to hash. Or directly comment out mode: ‘history’,

Conclusion: the above is the relevant information I know. If any boss knows other questions, you can leave a message and learn together.

 

An error occurs when es logstash is installed and running

Error message:

Expected one of [ \\t\\r\\n], \”#\”, \”input\”, \”filter\”, \”output\” at line 1, column 1 (byte 1)

Logstash run command:./logstash – f config MySQL/

SQL configuration file:/home/ES/logstash/bin/config MySQL/mysql-1.conf

SQL statement file:/home/ES/logstash/bin/config MySQL/tk.sql

JDBC configuration uses the configuration: statement_ filepath => “/home/es/logstash/bin/config-mysql/tk.sql”

terms of settlement:

        Put tk.sql in another file, for example:/home/ES/logstash/config/tk.sql

        As long as it is not in the same directory as the SQL configuration file, it is OK

React error boundary (What You Should Know & How to Solve)

  1. What is the error boundary?

Error boundary is a kind of react component. This component can capture JavaScript errors anywhere in its sub component tree, print these errors, and display the degraded UI , without rendering those sub-component trees that crash. Error boundaries catch errors during rendering, in the lifecycle method, and in the constructor of the entire component tree.

Note: the error boundary cannot capture the errors generated in the following scenarios

    event handling asynchronous code (such as setTimeout or requestanimationframe callback function) the server renders the errors thrown by itself (not its sub components)

If anyone (or both) of the two lifecycle methods static getderivedstatefromerror() or componentdidcatch() is defined in a class component, it becomes an error boundary. When an error is thrown, please use static getderivedstatefromerror() to render the alternate UI and componentdidcatch() to print the error message.

class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false };
  }

  static getDerivedStateFromError(error) {
    return { hasError: true };
  }

  componentDidCatch(error, errorInfo) {
    logErrorToMyService(error, errorInfo);
  }

  render() {
    if (this.state.hasError) {
      return <h1>Something went wrong.</h1>;
    }

    return this.props.children; 
  }
}

You can then use it as a regular component:

<ErrorBoundary>
  <MyWidget />
</ErrorBoundary>

The working mode of the error boundary is similar to the catch {} of JavaScript, except that the error boundary is only for the react component. Only the class component can be an error boundary component. In most cases, you only need to declare the error boundary component once and use it throughout the application.

Note that the error boundary can only catch the errors of its subcomponents, it cannot catch its own errors. If an error boundary cannot render the error message, the error will bubble to the nearest upper error boundary, which is also similar to the working mechanism of catch {} in JavaScript.

2. React error boundary

https://github.com/bvaughn/react-error-boundary
https://www.npmjs.com/package/react-error-boundary
The above address is the error boundary wheel encapsulated by the boss, which can be used directly. Please check the relevant documents for details

[Solved] Vue unit test syntax error: unexpected token ‘export‘

Paste error information to facilitate search engines to find similar errors

Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    D:\123\vue3-pro\h5-editor\node_modules\[email protected]@lodash-es\lodash.js:10
    export { default as add } from './add.js';
    ^^^^^^

    SyntaxError: Unexpected token 'export'

Solution

After checking online for a long time, I finally found the only way to solve my problem. If the common methods on the Internet are useless, friends can try

According to the reply to the question, you can configure the following in jest. Config. JS

"transformIgnorePatterns": [
  "<rootDir>/node_modules/(?!lodash-es)"
]

chunk-vendors.7142f8da.js:1 Uncaught SyntaxError: Unexpected token ‘<‘

This is what I Vue found by previewing with serve – s dist after packaging

reason   There is a problem with the parameters configured in vue.config.js

    publicPath: process.env.NODE_ENV === 'production'
    ?'/execl_forward/'
    : '/'

Then use NPM run build to package

  Cause static file error  

So I created EXECL in dist_ Forward folder put CSS and JS folders in it

Then it was solved  

Or use the default packaging method  

Vue.config.js

publicPath: './'

 

Error: PostCSS plugin postcss-pxtorem requires PostCSS 8

Question content:

Syntax Error: Error: PostCSS plugin postcss-pxtorem requires PostCSS 8.
Migration guide for end-users:
https://github.com/postcss/postcss/wiki/PostCSS-8-for-end-users


 @ ./src/styles/index.less 4:14-228 15:3-20:5 16:22-236
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://192.168.7.176:8081&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

Problem solving:

npm i [email protected]

[Solved] Vue uses webpack to package error: Createapp is not a function

Error message

_node_modules_vue_dist_vue_global_ js__WEBPACK_IMPORTED_MODULE_1___ default().createApp   is   not   a   function

There is a problem with the way Vue is introduced

The correct introduction method is

import { createApp } from 'vue';

var App = {
	data() {
		return {
			images: [{
					Picture: "img"
				},
				{
					Picture: "img2"
				}
			],
		}
	}
}
const app = createApp(App); // 将数据添加到Vue数据绑定上
const vm = app.mount("#app"); // 将数据绑定到指定id上

Document.querySelector(‘video‘).playbackRate [How to Solve]

The reason why I send this article is because I am used to playing at 1.75 times the speed, but station B has only 1.5 and 2, which makes me a headache. I originally had a plug-in that can speed up playback by 1.75 times, but I can’t use it recently. I don’t know why. So I searched for any way to modify the video playback speed of station B. Then there is the following.

The way to find out

Press F12 to enter the following code in the console

document.querySelector("video").playbackRate="16"

It is said that this method can modify the double speed.

report errors

I reported a mistake after using it. What’s the reason?Others open the source code, which is labeled by video. I don’t have it. So it must be wrong.

Others:

mine:

Solution:

As can be seen from the screenshot above, I right-click to add an ID attribute a to it
then enter the following code in the console,

			var video= document.getElementById('a');
			video.playbackRate=1.75

Done.

Error “NPM err” when starting Vue project! code ELIFECYCLE”

Since NPM and cnpm have been used together before, there is no problem. Today, when starting the Vue project, I encountered an error “NPM”   ERR!   code   “Elifecycle” was initially used with NPM   Run started and later changed to cnpm   Neither can run.

  After checking the information, it is mostly said on the Internet that it is because of node_ There is a problem with the installation of modules. The basic solution is to clear the cache and reinstall.

The following steps are summarized:

1、npm   cache   clean  — force

2、rm  – rf   node_ modules

3、rm  – rf   Package-lock.json (optional)

4、npm   install

 

 

[Solved] Syntax Error: TypeError: Cannot read property ‘parseComponent‘ of undefined

Syntax Error: TypeError: Cannot read property ‘parseComponent’ of undefined
Vue packages version mismatch

Failed to compile.

./src/App.vue
Module Error (from ./node_modules/vue-loader/lib/index.js):


Vue packages version mismatch:

- [email protected] (D:\site\hst_tech\hst_platform_frontend\node_modules\vue\dist\vue.runtime.common.js)
- [email protected] (D:\site\hst_tech\hst_platform_frontend\node_modules\vue-template-compiler\package.json)

This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.

Solution:

Set Vue template- [email protected] Version change Vue template- [email protected]

// Just change the version number to the same one
npm i -g [email protected] --save