I am attempting to show a string in reverse order using Vue. My template code is as follows:
<div id="app">
<reverse :msgreverse="message" :reverseMessage="reverseMessage()"></reverse>
</div>
Here is my script:
function reverseMessage(msg) {
return msg.split('').reverse().join('')
}
Vue.component('reverse', {
props:["msgreverse", "reverseMessage"],
template: '<p v-html="reverseMessage(msgreverse)"></p>'
})
var app = new Vue({
el: '#app',
data: {
message:'The message to reverse !',
}
})
However, when running this code, I encounter the following errors in the console:
TypeError: reverseMessage is not a function. (In 'reverseMessage()', 'reverseMessage' is undefined)
Error in render: "TypeError: reverseMessage is not a function. (In 'reverseMessage()', 'reverseMessage' is undefined)"
Property or method "reverseMessage" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property
Can someone advise me on how to make the <reverse>
component display a given string in reverse?