Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>taro-snippetsNew to Visual Studio Code? Get it now.
taro-snippets

taro-snippets

hacker

|
755 installs
| (0) | Free
生成taro组件代码以及使用taro方法提示
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Taro1.x snippets

丰富vscode的代码对于Taro框架的代码提示功能,$1表示创建代码片段后光标第一个所在区域,按tab键会依次切换到下一个位置

代码片段

taro-page

import Taro, { Component, Config } from '@tarojs/taro'
import { View } from '@tarojs/components'
import getShareCommon from '@/utils/share'

type IState = {}

/**
 * @cmdName {$2} $3 
 */
export default class  extends Component<{}, IState> {
  config: Config = {
    navigationBarTitleText: '$4',
    navigationBarTextStyle: 'black'
  }

  state: IState = {
    
  }

  componentWillMount() {}

  componentDidShow() {}

  onShareAppMessage() {
    return getShareCommon('$4', '$2')
  }

  render() {
    return (
      <View>$5</View>
    )
  }
}

taro-component

import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'

type IState = {}

type IProps = {}

export default class $1 extends Component<IProps, IState> {
  state: IState = {}

  componentWillMount() {
    
  }

  componentDidShow() {
    
  }

  componentWillReceiveProps(nextProps) {
    
  }

  render() {
    return (
      <View>$2</View>
    )
  }
}

eventCenter.on

Taro.eventCenter.on('$1', $2)

eventCenter.off

Taro.eventCenter.off('$1', $2)

showToast

Taro.showToast({ icon: '$1', title: '$2' })

showLoading

Taro.showLoading({ title: '$2' })

showModal

Taro.showModal({
  title: '$1',
  content: '$2'
})

uploadFile

Taro.uploadFile({
  url: '$1',
  name: '$2',
  filePath: '$3'
})

downloadFile

Taro.downloadFile({
  url: '$1',
  success(resp) {
    $2
  }
})

Taro.setStorage

Taro.setStorage({
  key: '$1',
  data: $2
})

getLocation

Taro.getLocation({
  type: 'gcj02',
  success(resp: { latitude: number, longitude: number, speed: number, accuracy: number, altitude: number, verticalAccuracy: number, horizontalAccuracy: number }) {
    $1
  }
})

openLocation

Taro.openLocation({
  latitude: $1,
  longitude: $2
})

onShareAppMessage

onShareAppMessage () {
  return {
    title: '$1',
  }
}

componentWillMount

componentWillMount() {
  $1
}

......

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft