简体   繁体   中英

Locutus in VueJS template engine

How can i implement Locutus in my VueJS application? I am using 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.

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:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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