애플릿이 현재 경로와 파라미터를 가져옵니다

5032 단어 애플릿
여기서 여러분과 공유하자면 저는 작은 프로그램을 개발하는 과정에서 현재의 작은 프로그램 경로와 파라미터의 사용법, 그리고 부딪힌 구덩이를 얻었습니다.
기본용법
경로 가져오기
	var pages = getCurrentPages(); 				//       
	var currentPage = pages[pages.length - 1]   //         
	var url =  currentPage.route 				//    url
	console.log(url); 							//  url

----경로의 매개 변수 가져오기
방법 1
		var pages = getCurrentPages(); 				//       
		var currentPage = pages[pages.length - 1] 	//         
		const options = currentPage.options 		//         
		console.log(options); 						//         

메서드2: onLoad에서 사용해야 함
		onLoad: function (options) {
			console.log(options) //         
		}

방갱 지침서
  • currentPage is not defined; opyions is not defined; 세심하지 않은 나는 앞의 두 마디를 적게 써서 매개 변수를 직접 인용할 수 있다고 생각했다
  • 		var pages = getCurrentPages(); 				//        
    		var currentPage = pages[pages.length - 1] 	//        
    		const options = currentPage.options 		
    		console.log(options); 						
    
  • this의 사용을 주의하고 전역 변수를 정의해서 호출해야 할 때가 있다
  • 		onLoad: function (options) {
        	var that = this;
    
    		 that.setData({
    		         id: 1, 
    		   })
    		}				
    

    좋은 웹페이지 즐겨찾기