简体   繁体   English

VueJS模板引擎中的Locutus

[英]Locutus in VueJS template engine

How can i implement Locutus in my VueJS application? 如何在VueJS应用程序中实现Locutus I am using webpack. 我正在使用webpack。

I tried to to the following in my single file component: 我在单个文件组件中尝试执行以下操作:

<template>
  <div>{{ nl2br('My string here') }}</div>
</template>

<script>
var nl2br = require('locutus/php/strings/nl2br');

export default {
  // VueJS
}
</script>

It says that my template: 它说我的模板:

can't render because $vm.nl2br, doesn't exists. 无法渲染,因为$ vm.nl2br不存在。

You can not access methods from other libraries in the view, You can use those in any of vue methods and invoke that method from vue template, so you cab have something like following: 您不能从视图中的其他库访问方法,可以在任何vue方法中使用这些方法,并从vue模板调用该方法,因此您可以进行如下操作:

<template>
  <div>{{ getFromNl2br('My string here') }}</div>
</template>

<script>
var nl2br = require('locutus/php/strings/nl2br');

export default {
  methods: {
     getFromNl2br: function(str) {
        return nl2br(str)
     }
  }
}
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM