我正在嘗試vue-currency-input使用 vue 2.6 來實作插件。
"vue": "^2.6.12",
https://dm4t2.github.io/vue-currency-input/guide.html
但是在檔案中僅詳細說明了此資訊:
兼容性
Vue Currency Input 3.x 需要 Vue 2.7 或 Vue 3。對于 Vue 2.6 或更早版本,請將 Vue Currency Input 2.x 與 Vue Composition API 插件一起使用。
“與 Vue Composition API 插件一起使用”是什么意思?
我安裝了這些包:
npm install vue-currency-input
npm install @vue/composition-api
然后在main.js檔案中我添加了以下幾行import Vue from "vue";:
import VueCompositionAPI from "@vue/composition-api";
Vue.use(VueCompositionAPI);
然后我用這個創建組件 CurrencyInput.vue:
<template>
<input ref="inputRef" type="text" />
</template>
<script>
import { useCurrencyInput } from "vue-currency-input";
export default {
name: "oCurrencyInput",
props: {
value: Number,
options: Object,
},
setup(props) {
const { inputRef } = useCurrencyInput(props.options);
return { inputRef };
},
};
</script>
然后我試著像往常一樣使用它。
<template>
<CurrencyInput
v-model="value"
:options="{ currency: 'EUR' }"
/>
</template>
<script>
import CurrencyInput from './CurrencyInput'
export default {
name: 'App',
components: { CurrencyInput },
data: () => ({ value: 1234 })
}
</script>
最后,它不作業并顯示這些警告:
WARNING Compiled with 5 warnings 10:02:52 PM
warning in ./node_modules/vue-currency-input/dist/index.mjs
"export 'computed' was not found in 'vue'
warning in ./node_modules/vue-currency-input/dist/index.mjs
"export 'getCurrentInstance' was not found in 'vue'
warning in ./node_modules/vue-currency-input/dist/index.mjs
"export 'ref' was not found in 'vue'
warning in ./node_modules/vue-currency-input/dist/index.mjs
"export 'version' was not found in 'vue'
warning in ./node_modules/vue-currency-input/dist/index.mjs
"export 'watch' was not found in 'vue'
另外,我嘗試以這樣的方式添加 @vue/composition-api :
<template>
<input ref="inputRef" type="text" />
</template>
<script>
import { useCurrencyInput } from "vue-currency-input";
import { ref, reactive } from "@vue/composition-api";
export default {
name: "oCurrencyInput",
props: {
modelValue: value,
options: Object,
},
setup(props) {
const { inputRef } = ref(useCurrencyInput(props.options));
return { inputRef };
},
};
</script>
還是行不通。最后,我看到vuejs input witdh mask new money但我找不到適合我的答案。
uj5u.com熱心網友回復:
兼容性
Vue Currency Input 3.x 需要 Vue 2.7 或 Vue 3。對于 Vue 2.6 或更早版本,請將 Vue Currency Input 2.x 與 Vue Composition API 插件一起使用。
你正在使用 Vue 2.6
因此npm install vue-currency-input,您必須使用npm i [email protected]
“與 Vue Composition API 插件一起使用”是什么意思?
是的,就是安裝和使用@vue/composition-api docs
您也不應該使用當前檔案。我找不到 2.x 的檔案(因為站點)只有 v1.x 檔案的鏈接,但您可以直接在 Github 上輕松閱讀 Markdown 格式的檔案。這是 v2.x 的檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/535547.html
