• vue2 项目中嵌入视频


    案例:

    ps:  视频存放在静态文件夹里面

        public文件夹:一般用于存放一些静态资源文件,例如图片,视频,音频等资源文件。需要特别注意的是webpack在进行打包的时候,会将public中的所有静态资源原封不动的进行打包

    代码

    1. <template>
    2. <div class="schematicDiagramIndex">
    3. <el-container>
    4. <el-aside width="20rem">
    5. <div style="height: 100%;overflow-y: scroll">
    6. <el-input
    7. placeholder="输入关键字进行过滤"
    8. v-model="filterText"
    9. >
    10. el-input>
    11. <el-tree
    12. class="filter-tree"
    13. :data="CompanyLeftData"
    14. :props="defaultProps"
    15. default-expand-all
    16. :expand-on-click-node="false"
    17. :default-checked-keys="[1]"
    18. highlight-current
    19. node-key="value"
    20. @node-click="handleNodeClick"
    21. :filter-node-method="filterNode"
    22. ref="treeList"
    23. :height="heights"
    24. >
    25. el-tree>
    26. div>
    27. el-aside>
    28. <el-divider direction="vertical" style="border: 1px solid #ccc; }" >el-divider>
    29. <el-main>
    30. <video
    31. id="video1"
    32. controls
    33. class="video1"
    34. loop="loop"
    35. ref="video"
    36. :height="heights"
    37. >
    38. <source :src="video" type="video/mp4" />
    39. 您的浏览器不支持 HTML5 video 标签。
    40. video>
    41. el-main>
    42. el-container>
    43. div>
    44. template>
    45. <script>
    46. export default {
    47. name: 'schematicDiagramIndex',
    48. data () {
    49. return {
    50. defaultProps: {
    51. children: "children",
    52. label: "label",
    53. id: "ID",
    54. },
    55. CompanyLeftData:[
    56. {
    57. value: '1',
    58. label: '油泵车',
    59. children: [
    60. {
    61. value: '1-1',
    62. label: '双系统独立自循环',
    63. },
    64. {
    65. value: '1-2',
    66. label: '箱体组成',
    67. },
    68. {
    69. value: '1-3',
    70. label: '电气系统组成',
    71. },
    72. {
    73. value: '1-4',
    74. label: '双系统合流自循环',
    75. },
    76. {
    77. value: '1-5',
    78. label: '液压系统排气',
    79. },
    80. {
    81. value: '1-6',
    82. label: '液压系统组成',
    83. },
    84. {
    85. value: '1-7',
    86. label: '动力系统组成',
    87. },
    88. {
    89. value: '1-8',
    90. label: '油液固体颗粒污染自检和取样检测',
    91. },
    92. {
    93. value: '1-9',
    94. label: '双系统独立输出',
    95. },
    96. {
    97. value: '1-10',
    98. label: '双系统合流输出',
    99. },
    100. {
    101. value: '1-11',
    102. label: '双系统合流输出',
    103. },
    104. ],
    105. },
    106. {
    107. value: '2',
    108. label: '电源车',
    109. children: [
    110. {
    111. value: '2-1',
    112. label: '',
    113. },
    114. ],
    115. },
    116. ],
    117. filterText:"",
    118. video:"",
    119. heights:"",//高度
    120. }
    121. },
    122. created() {
    123. },mounted() {
    124. this.$nextTick(() => {
    125. this.$refs.treeList.$el.getBoundingClientRect().top; //表格距离浏览器的高度
    126. // this.$refs.video.$el.getBoundingClientRect().top; //表格距离浏览器的高度
    127. // 根据浏览器高度设置初始高度
    128. this.heights =
    129. window.innerHeight - this.$refs.treeList.$el.offsetTop - 150 ;
    130. // 监听浏览器高度变化,修改表格高度
    131. window.onresize = () => {
    132. this.heights =
    133. window.innerHeight - this.$refs.treeList.$el.offsetTop - 150 ;
    134. };
    135. console.log(this.heights, 1);
    136. });
    137. this.setCurrentKeyData()
    138. },
    139. methods: {
    140. //进行切换数据(点击事件)
    141. handleNodeClick(data, checked) {
    142. this.$refs.video.load()
    143. if (checked) {
    144. //进行勾选的数据
    145. this.$refs.treeList.setCheckedNodes([data]);
    146. this.video="/static/oil-"+data.value+".mp4"
    147. }
    148. },
    149. //进行模糊查询
    150. filterNode(value, data) {
    151. if (!value) return true;
    152. return data.label.indexOf(value) !== -1;
    153. },
    154. // 默认选中
    155. setCurrentKeyData() {
    156. this.$nextTick(() => {
    157. this.$refs.treeList &&
    158. this.$refs.treeList.setCurrentKey(this.CompanyLeftData[0].children[0].value);
    159. this.handleNodeClick(this.CompanyLeftData[0].children[0], true);
    160. });
    161. },
    162. },
    163. computed: {},
    164. watch: {
    165. filterText(val) {
    166. this.$refs.treeList.filter(val);
    167. }
    168. },
    169. }
    170. script>
    171. <style scoped>
    172. .schematicDiagramIndex{
    173. width: 100%;
    174. /*height: 100%;*/
    175. /*height: 45rem ;*/
    176. }
    177. .video1{
    178. width: 100%;
    179. /*height: 85%;*/
    180. }
    181. ::v-deep .el-tree-node__content {
    182. color: black;
    183. font-size: 14px;
    184. font-weight: 400;
    185. margin: 5px;
    186. }
    187. /*::v-deep .el-input__wrapper {*/
    188. /* background-color: transparent !important;*/
    189. /*}*/
    190. ::v-deep .el-tree {
    191. background-color: transparent;
    192. --el-tree-node-hover-bg-color: #b5b7b7;
    193. margin-top: 20px;
    194. padding-top: 10px;
    195. padding-bottom: 10px;
    196. /*background: url("@/assets/imgList/memuBG.png") no-repeat;*/
    197. background-size: 100% 100%;
    198. }
    199. ::v-deep
    200. .el-tree--highlight-current
    201. .el-tree-node.is-current
    202. > .el-tree-node__content {
    203. background-color: #1a518c;
    204. color: #fcfbfb;
    205. }
    206. .filter-tree {
    207. padding-top: 1%;
    208. /*height: 44rem;*/
    209. /*height: 100%;*/
    210. }
    211. style>

    参考:HTML video autoplay 属性 | 菜鸟教程

  • 相关阅读:
    还没用过Idea的这几款插件?那你也太out了
    JS导出文本为文本文件
    国产猫粮高端化难题不少,网易天成拿什么出众?
    10.5汇编语言整理
    y50.第三章 Kubernetes从入门到精通 -- k8s实战案例(二三)
    潮玩游戏潮玩宇宙大逃杀游戏
    keep-alive动态移除缓存
    Java 后台重定向一个带参数的地址,前端要在地址中获取参数,并保存在Vue中,以便跳转到界面的时候世界使用
    CentOS 7上安装Python 3.11.5,支持Django
    Spring SpEL表达式语言
  • 原文地址:https://blog.csdn.net/CMDN123456/article/details/132909252