如何在模板中使用其他vue中的组件

问题描述 投票:0回答:1

我在A.js文件中写了一个函数,但是我想用它来处理B.vue模板中的字符串,但我得到错误TypeError:_vm.translatecomponent不是函数,我是vue的新手,你能告诉我吗?我有什么不对?

A.js 
export function traslate(originalValue){
  return originalValue
} 

B.vue 
 .......
 <el-button type="primary">{{translatecomponent(searchFunc.queryText)}}</el-button>
</template>

<script>
import { translatecomponent } from '@/directive/index' //this is file path

提前致谢

javascript vue.js vue-component
1个回答
1
投票

它必须在方法中声明。

B.vue

<script>
  import { translatecomponent } from '@/directive/index' //this is file path

  export default {
    ...
    methods:{ translatecomponent }
  }
</script>
© www.soinside.com 2019 - 2024. All rights reserved.