This time I will bring you what are the precautions for using Vue.js, what are the precautions for using Vue.js, the following is a practical case, let's take a look.
1. When passing parameters, there must be a space between the second parameter and the preceding comma
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(items))
2. Pay attention to the space
Correct format
<script>import Store from './store'console.log(Store)export default { ... }</script> 错误格式 <script> import Store from './store' console.log(Store)export default { ... }</script>
3. The parent passes parameters to the child component
In the parent component
//模板中<template> <div id="app"> //之前老版本 <conponent-a msgfromfather="父亲传给儿子!"></conponent-a> <ConponentA msgfromfather="父亲传给儿子!"></ConponentA> </div></template>//Js<script>export default { //注册ConponentA components: {ConponentA}, }</script>
In the child component
<template> <div class="hello"> <h1 id="nbsp-msg-nbsp">{{ msg }}</h1> <button v-on:click="onClickMe()">点我啊,小样儿</button> </div></template><script> export default { data () { return { msg: 'hello from component A!' } }, //props 可以是数组或对象,用于接收来自父组件的数据 props: ['msgfromfather'], methods: { onClickMe: function () { //打印从父组件传过来的值 console.log(this.msgfromfather) } } }</script><style scoped> h1 { font-weight: normal; }</style>
4. The child passes parameters to the parent component
The son tells The father needs to use vm.$emit and vm.$on to trigger events and listen for events
In child components
<template> <div class="hello"> <h1 id="nbsp-msg-nbsp">{{ msg }}</h1> <h1 id="msgfromfather">{{msgfromfather}}</h1> <button v-on:click="onClickMe()">点我啊,小样儿</button> </div></template><script> export default { data () { return { msg: 'hello from component A!' } }, methods: { onClickMe: function () {// 子传父 触发当前实例上的事件 this.$emit('child-tell-me-something', this.msg) } } }</script><style scoped> h1 { font-weight: normal; }</style>
In parent components
<template> <div id="app"> <p>child tells me: {{childWorlds}}</p> <ConponentA msgfromfather="父亲传给儿子!" v-on:child-tell-me-something="listenToMyBoy"></ConponentA> </div></template><script>import ConponentA from './components/componentA.vue'export default { data: function () { return { childWorlds: '' } }, components: {ConponentA}, watch: { items: { handler: function (items) { Store.save(items) }, deep: true } }, methods: { //监听 listenToMyBoy: function (msg) { console.log(msg) this.childWorlds = msg } } }</script>
In addition to this method, there are For other methods, please see the Vue.js official website
Self-defining componentSpecify attributesData type
export default { props: { slides: { type: Array, //数组 default: [] //默认值 } }, 在加载完毕执行某个方法 mounted () { this.loadxxx() }@mouseover="xxxx" Mouse enter ( Execute an event), @mouseout="xxxx" The mouse moves out (execute an event);Transiotions animation is invalid for left and right, etc. To achieve animation effects, you can only use the x-axis;slot slotthis.abc = false is equivalent to this['abc'] = falseThe parent component style does not add scoped, so that its child components can share it The style, that is to say, the style of the child component can be written in the parent component.
<!-- Add "scoped" attribute to limit CSS to this component only --><style>......</style>& represents the parent element
<!--css书写规范 可被继承的写在前面,不让继承的的写在后面--><style lang="stylus" rel="stylesheet/stylus"> #app .tab display: flex width: 100% height: 40px line-height: 40px .tab-item flex: 1 text-align: center /* & > a & 代表父元素 tab-item 子元素选择器 */ & > a display: block font-style: 14px color: rgb(77,85,93) &.active color: rgb(240,20,20)</style>1 pixel border implementation
can be used on the PC Through the following settings, it is achieved.
border-bottom: 1px solid rgba(7,17,27,0.1)I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website! Recommended reading:
Deep into the movement of JS in JavaScript
Deep into the advanced application of DOM in JavaScript
In-depth knowledge of JavaScript
The above is the detailed content of What are the precautions for using Vue.js?. For more information, please follow other related articles on the PHP Chinese website!

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools