Skip to content

Camera 相机

支持平台

安卓iosweb微信小程序支付宝小程序QQ小程序
xxx

示例

html
<template>
	<t-page title='自定义相机' class="p.30">
		<t-card title="Camrea 相机" sub-title="本相机组件设计简洁,易于集成,满足多样化的拍摄需求">
		</t-card>
		<t-col class="tdr-tdb-mt.30">
			<t-camrea @take="getPhoto" ref="camrea" style="width:100%;height:320px"></t-camrea>
		</t-col>

		<t-row class="fjcb-mt.30">
			<t-button class="w.31%" @click="open">打开相机</t-button>
			<t-button class="w.31%" @click="close">关闭相机</t-button>
			<t-button class="w.31%" @click="take">拍照</t-button>
		</t-row>
		<t-section class="mtb.30" title='预览图'></t-section>
		<t-col class="tdr">
			<t-image class="w.100%" v-if="urlSrc!=''" :src="urlSrc"></t-image>
		</t-col>
		<view style="height: 50px;"></view>
	</t-page>
</template>


<script>
	export default {
		data() {
			return {
				urlSrc: ''
			}
		},
		methods: {
			open() {
				let el = (this.$refs['camrea'] as TCamreaComponentPublicInstance)
				el.open()
			},
			close() {
				let el = (this.$refs['camrea'] as TCamreaComponentPublicInstance)
				el.close()
			},
			take() {
				let el = (this.$refs['camrea'] as TCamreaComponentPublicInstance)
				el.take()
			},
			getPhoto(result : string) {
				this.urlSrc = result
			}
		}
	}
</script>

Props

名称描述类型默认值可选值
class组件的类名,用于自定义样式String--

Events

事件名描述回调参数版本
take拍照成功后触发,传递照片路径照片路径-

Methods

名称描述
open打开相机
close关闭相机
take拍照
getPhoto获取拍照结果

Slots

名称描述
default默认插槽,用于放置相机组件