javascript - 如何在 vue js 2 上将变量放入 href 中?

标签 javascript vue.js vuejs2

当我运行此命令时:{{nextPage}}

结果

http://chelseashop.dev/search-result?page=2

但是当我输入这样的 href 时:

<template>
    <nav aria-label="Page navigation">
        <ul class="pagination">
            ...
            <li>
                <a :href="{{nextPage}}" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>
        </ul>
    </nav>
</template>
<script>
    export default{
        props:['total', 'data', 'nextPage', 'prevPage'],
        ...
    }
</script>

存在这样的错误:

template syntax error - invalid expression: :href="{{nextPage}}"

如何解决该错误?

最佳答案

v-bind 表达式直接作为 JavaScript 执行。因此,它们不需要插值。

你只是想要

<a :href="nextPage" aria-label="Next">

参见Template Syntax - Attributes

Mustaches cannot be used inside HTML attributes, instead use a v-bind directive

关于javascript - 如何在 vue js 2 上将变量放入 href 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41949256/

相关文章:

javascript - 尝试让 iframe 通过按钮切换

javascript - 如何在输入的数字范围内查找质数

vue-component - 如何在 Vue 中公开包装的 &lt;input&gt;?

vue.js - 将 vuex store 的一部分作为 action 的负载分派(dispatch)是否正确?

javascript - 新建vue实例的main变量在哪里使用

javascript - 如何在表格中添加按钮

javascript - 从文本框中过滤 gridview 时显示一些消息

webpack - 无法读取未定义的 vue 的属性 'post'

javascript - 如果外部加载 JS 文件,Vue 无法注册组件

javascript - 为什么 VueJS 在推送数组后自动重新加载?