javascript - 如何更改 vue-cookie-law 默认 Props
问题描述
我正在尝试buttonText
使用 Props 更改组件 vue-cookie-law 的默认值。
我可以直接从 node_modules 插件源代码中更改默认值,但我想从 Vue 单文件组件中更改它。
vue-cookie-law - https://www.npmjs.com/package/vue-cookie-law
道具默认类型
buttonText:'知道了!'
由于我之前没有使用过 Props,所以我一直在尝试一些东西,下面是我的 CookieLaw.vue 组件
<template>
<footer>
<cookie-law theme="base">
<div slot="message">
We use cookies to enhance your experience. By continuing to visit our site you agree to our use of cookies.
<router-link to="terms_and_conditions">View Policy</router-link>
</div>
</cookie-law>
</footer>
</template>
<script>
import CookieLaw from "vue-cookie-law";
export default {
props: {
buttonText: {
default: "Agree"
}
},
components: { CookieLaw }
};
</script>
道具不会改变buttonText
.
解决方案
buttonText
是您所知道的组件的默认道具之一vue-cookie-law
......不是父组件(您导入它的那个)所以您必须将它们绑定到它自己的组件:
<cookie-law theme="base" buttonText="Agree">
...
</cookie-law>
或者绑定一个动态值:
<script>
import CookieLaw from "vue-cookie-law";
export default {
data() {
return {
text: 'Agree'
}
}
components: {
CookieLaw
}
}; <
</script>
<cookie-law theme="base" :buttonText="text">
...
</cookie-law>
推荐阅读
- java - 适用于 Android 的水平动画滑动菜单
- c# - 可以在不等待循环结束的情况下获得 ForEach 内每个 API 调用的响应吗?
- bash - 在 shell/unix 中下载和重命名链接
- c++ - 为什么 GCC 为本地 C 结构分配“太多”堆栈空间?
- c# - Selenium C# - Sendkeys 方法不输入 ^~ 字符
- python - 找不到文本文件
- json - 这个 bash 脚本有什么问题
- excel - 有没有办法从 txt.files 或 Excel.files 在 Ovtave 中自动开发矩阵?
- android - 为什么我得到这个 - Android App Bundle 使用错误的密钥签名。确保您的 App Bundle 使用正确的签名密钥进行签名,然后重试
- sql - 子串替换