例如:vue-fullscreen
<template> <div class="Test"> <fullscreen ref="fullscreen" @change="fullscreenChange" >
<el-button @click="toggle">全屏</el-button> something </fullscreen> </div> </template> <script lang="ts"> import { Vue, Component, Prop, Watch } from 'vue-property-decorator';// @ts-ignore import fullscreen from 'vue-fullscreen'; Vue.use(fullscreen); @Component({}) export default class Test extends Vue { toggle() { (this.$refs.fullscreen as fullscreen).toggle(); // !!!! as后面的fullscreen是引入后组件的名称 } fullscreenChange(status: boolean) { this.fullscreen = status; } } </script> <style lang="less" scoped> .Test{} </style>