html - html属性中的vuejs变量

标签 html vue.js

所以我试图将一个元素的 src 设置为一个 js 变量,但它不起作用。我尝试了几种方法,但无法正常工作。这是一种方法

<source src="{{ this.show.podcastUrl }}" type="audio/mpeg">

我也试过

<source v-bind:src="{{ this.show.podcastUrl }}" type="audio/mpeg">

<source :src="{{ this.show.podcastUrl }}" type="audio/mpeg">

我做错了什么?这是我的组件

<template>
    <div class="panel panel-default">
        <div class="panel-heading">
            {{ this.show.name }}
            <div class="pull-right">
                {{ this.show.number }}
            </div>
        </div>
        <div class="panel-body">
            <ul>
                <li>Air Date: </li>
                <li>
                    <audio controls>
                        <source v-bind:src="{{ this.show.podcastUrl }}" type="audio/mpeg">
                    </audio>
                </li>
            </ul>
        </div>
    </div>
</template>


<script>
    export default {
        mounted() {
            console.log(this.show);
        },

        props: {
            show: {
                type: Object,
                required: true
            }
        }
    }
</script>

最佳答案

这是因为您在 v-bind 指令中使用了 mustaches - 这是不允许的。

Mustaches {{}} 到 VueJS 与模板相关,v-bind 被传递给 JS - 所以作为模板引擎一部分的 mustaches 不允许进入 v-bind 指令。

这应该是正确的方式:

<source :src="show.podcastUrl" type="audio/mpeg">

这里也不需要this

关于html - html属性中的vuejs变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41289941/

相关文章:

javascript - 仅当 Vuex 存储中的数据为 "stale"或不存在时才调用 API

javascript - jQuery 无法识别动态插入的 DOM 元素?

html - 如何对 flex-children 进行分组并向不同的方向展示它们?

javascript - 如何从组件的操作中动态改变 Storybook v6 中的 "args"?

javascript - 如何在生产模式下查看错误 - nuxtjs

vue.js - Vue 3 组合 API,如何在 setup() 函数中获取上下文父属性?

javascript - Vue router 路由的安全性

html - 如何创建以下div?

javascript - 当上面的一个 html5 音频完成时播放下一个 html5 音频

html - 事件边框属性突然停止在 chrome 中工作