전역 메소드 생성 및 호출: 1. vue 프로젝트의 src 디렉터리에 있는 파일에서 메소드를 사용자 정의합니다. 2. "main.js" 파일의 import 문을 사용하여 사용자 정의 메소드를 도입하고 해당 메소드를 마운트합니다. 3. 필요한 페이지에서 "$vue instance.method name()" 문을 사용하여 메서드를 호출합니다.
이 튜토리얼의 운영 환경: Windows 7 시스템, vue 버전 2.9.6, DELL G3 컴퓨터.
Vue.js는 전역 메서드를 생성하고 호출합니다
vue 프로젝트에서 먼저 src의 모든 파일 아래에 메서드를 사용자 정의합니다. 예를 들어 다음과 같습니다
transNum (num) { if (typeof (num) === 'undefined') { return 0 } else { let oldNum = num.toString().trim() let len = oldNum.length if (len <= 3) { return num } else { let newNum = oldNum.substr(0, len - 3) + '.' + oldNum.charAt(len - 3) + 'k' return newNum } } }
방법 1: Vue 인스턴스에 마운트
예: vue 프로젝트의 main.js 파일에 이 메서드를 도입하고 이 메서드를 vue 인스턴스에 마운트합니다. main.js 파일
import myutil from '@/common/utils/util.js' Vue.prototype.$myutil = myutil
에 다음 코드를 추가하면
$myutil.transNum(num)
를 직접 사용할 수 있습니다. 방법 2: 가져오기를 통해
을 가져오고 필요한 파일의
import util from '@/common/utils/util.js''
메서드를 호출합니다. call this method
util.transNum(num)
참고:
메서드 호출을 {
{}}
에 작성하려면 첫 번째 방법을 통해서만 메서드를 소개할 수 있습니다. 구체적인 이유는 vue의 수명 주기와 관련이 있으므로 다루지 않겠습니다. 세부 사항으로.
관련 추천: "vue.js Tutorial"
위 내용은 vuejs에서 전역 메소드를 생성하고 호출하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

클래스 선택기 및 ID 선택기의 사용은 특정 사용 사례에 따라 다릅니다. 1) 클래스 선택기는 다중 요소, 재사용 가능한 스타일에 적합하며 2) ID 선택기는 고유 한 요소 및 특정 스타일에 적합합니다. 클래스 선택기는 더 유연하며 ID 선택기는 처리하기가 더 빠르지 만 코드 유지 보수에 영향을 줄 수 있습니다.

TheKeyGoalSandMotivationSBehindhtml5WeretoEnhancesemanticstructure, EverneMultImediasupport, andensureBetTerferfortPerformanceAndCompatibilityAcrossDevices, DrivenBytheneedToaddresshtml4'SlimitationsAndModernWebDemands.1) HTMl5AIMEDTOMPROVETUCETUR

idsareUniqueAndusedForsingleElements, whileclassesareuseableforlultipleements.1) useidsforuniqueElementsLikeSpecificheader.2) USECLASSESFORCONSESTENTSTYLINGACROSSMultipleEmentements likeSlikeButtons

html5aimstoenhancewebaccessibility, Interactivity, andefficiency

html5isnotparticular indifficulttousebutreequiresunderstandingStandingStandingStandingStandingStandingStandingStandingStandingStandingStandingStandingS

아니요, 당신은 uplemultipleidsinthesamedom.1) idsmustbeuniqueperhtmlspecification, andusingduplicatescancauseSconsistentBrowserBehavior.2) useclassesforstylingmultipleelements, attributesectorscendats eftibutes 및 descenderfortrecture

html5aimstoenhancewebcapabilities, MakingItmoredynamic, Interactive, and Accessible.1) itsupportsmultimediaelementslikeand, 2) SemanticlementsImpreveAcessibilityandCodeReardability.3) 특징적인 부대, 응답 Whebappl

html5aimstoenhancewebdevelopmentandusereerexperiencetroughsemanticstructure, multimediaintegration 및 performanceimprovements


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.